POV-Ray : Newsgroups : povray.off-topic : Locking references Server Time
4 Sep 2024 19:23:30 EDT (-0400)
  Locking references (Message 1 to 10 of 33)  
Goto Latest 10 Messages Next 10 Messages >>>
From: Invisible
Subject: Locking references
Date: 9 Nov 2009 05:43:30
Message: <4af7f252@news.povray.org>
I have heard it suggested that if every thread in a program takes 
whatever locks it needs to take in sorted order, it is guaranteed that 
deadlock can never occur.

Is this correct? And does anybody have a reference I can site?


Post a reply to this message

From: Paul Fuller
Subject: Re: Locking references
Date: 9 Nov 2009 08:10:38
Message: <4af814ce$1@news.povray.org>
I'd think this is immediately obvious.

One issue is that a thread does not always know what locks it needs 
before the fact.  And if you hold a lock and want to get another with a 
lower key then you have to release the lock you hold then go back and 
get them in the right order.

As to references, Wikipedia 'Deadlock' article is a decent starting 
point.  Many more erudite references are given there.


Post a reply to this message

From: Invisible
Subject: Re: Locking references
Date: 9 Nov 2009 08:26:29
Message: <4af81885$1@news.povray.org>
Paul Fuller wrote:
> I'd think this is immediately obvious.

Not to me. ;-)

> One issue is that a thread does not always know what locks it needs 
> before the fact.

Yes, this is the killer. Often it's not possible to know what locks you 
want until you read some data (which you have to lock first). And if you 
release the locks, somebody else could come and change the data...

> As to references, Wikipedia 'Deadlock' article is a decent starting 
> point.  Many more erudite references are given there.

OK, I'll take a look.


Post a reply to this message

From: Stefan Viljoen
Subject: Re: Locking references
Date: 9 Nov 2009 08:46:56
Message: <4af81d4f@news.povray.org>
Invisible wrote:

> Paul Fuller wrote:

>> One issue is that a thread does not always know what locks it needs
>> before the fact.
> 
> Yes, this is the killer. Often it's not possible to know what locks you
> want until you read some data (which you have to lock first). And if you
> release the locks, somebody else could come and change the data...

Isn't that the point? I've never worked with a low-level locking setup, but
I implemented a high-level one in the CMS I'm currently working on. If
somebody accesses a specific item, it is locked with a timeout. If he
doesn't commit changes within 15 minutes (or whatever is set), he "loses"
the lock, and somebody else can edit.

I.e. releasing a lock = it's ok for somebody else to change the data. You
have the lock = everybody else is blocked from changing the data?

-- 
Stefan Viljoen


Post a reply to this message

From: Invisible
Subject: Re: Locking references
Date: 9 Nov 2009 08:52:22
Message: <4af81e96$1@news.povray.org>
>>> One issue is that a thread does not always know what locks it needs
>>> before the fact.
>> Yes, this is the killer. Often it's not possible to know what locks you
>> want until you read some data (which you have to lock first). And if you
>> release the locks, somebody else could come and change the data...
> 
> Isn't that the point? I've never worked with a low-level locking setup, but
> I implemented a high-level one in the CMS I'm currently working on. If
> somebody accesses a specific item, it is locked with a timeout. If he
> doesn't commit changes within 15 minutes (or whatever is set), he "loses"
> the lock, and somebody else can edit.
> 
> I.e. releasing a lock = it's ok for somebody else to change the data. You
> have the lock = everybody else is blocked from changing the data?

My point is, you can't just go "I've got lock 7 and lock 13, and now I 
need lock 2, so I'll just release lock 7 and lock 13, then take lock 2 
and take back lock 7 and lock 13". In between releasing the locks and 
taking them back, something could change. You need a better plan than that.


Post a reply to this message

From: Stefan Viljoen
Subject: Re: Locking references
Date: 9 Nov 2009 09:19:30
Message: <4af824f1@news.povray.org>
Invisible wrote:

> My point is, you can't just go "I've got lock 7 and lock 13, and now I
> need lock 2, so I'll just release lock 7 and lock 13, then take lock 2
> and take back lock 7 and lock 13". In between releasing the locks and
> taking them back, something could change. You need a better plan than
> that.

Isn't this what a mutex (like it is implemented in the Linux kernel) is for? 

Wik it a bit, I think it might be a partial answer to your original
question... :)
-- 
Stefan Viljoen


Post a reply to this message

From: Paul Fuller
Subject: Re: Locking references
Date: 9 Nov 2009 09:36:13
Message: <4af828dd@news.povray.org>
> OK, I'll take a look.

Is this just theoretical interest or is there an actual problem that you 
are trying to solve ?

In non-trivial cases like databases and operating systems the 
possibility of deadlocks cannot be eliminated entirely.  The designers 
seek to reduce the chances by good design but they also have to 
implement 'deadlock detection' and 'deadlock resolution'.


Post a reply to this message

From: Invisible
Subject: Re: Locking references
Date: 9 Nov 2009 09:46:06
Message: <4af82b2e$1@news.povray.org>
I just saw this:

http://en.wikipedia.org/wiki/Gridlock

I can't help thinking that this should be an XKCD strip. I can just 
imagine Black Hat Guy doing something to the timing of the traffic 
signals to induce a mathematically indefinite deadly embrace. (And throw 
in a pun or two in the process... Get it?... Process?)


Post a reply to this message

From: Invisible
Subject: Re: Locking references
Date: 9 Nov 2009 09:46:41
Message: <4af82b51$1@news.povray.org>
Paul Fuller wrote:
>> OK, I'll take a look.
> 
> Is this just theoretical interest or is there an actual problem that you 
> are trying to solve ?
> 
> In non-trivial cases like databases and operating systems the 
> possibility of deadlocks cannot be eliminated entirely.  The designers 
> seek to reduce the chances by good design but they also have to 
> implement 'deadlock detection' and 'deadlock resolution'.

I've just implemented a solution; I'm trying to write it up. ;-)


Post a reply to this message

From: Invisible
Subject: Re: Locking references
Date: 9 Nov 2009 09:49:17
Message: <4af82bed@news.povray.org>
http://en.wikipedia.org/wiki/Deadlock_provision

...so, it's like the deadlock resolution algorithm where you randomly 
terminate one process, except that you're terminating somebody's 
*employment* instead?

Wow, that's pretty harsh. :-D


Post a reply to this message

Goto Latest 10 Messages Next 10 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.