Boost logo

Boost Users :

Subject: Re: [Boost-users] [Thread] order of shared_lock and unique_lock acquisitions
From: Zeljko Vrba (zvrba_at_[hidden])
Date: 2009-01-09 07:30:50


On Fri, Jan 09, 2009 at 01:02:36PM +0100, Roland Bock wrote:
>
> Is there a way to determine the order in which the (shared) locks are
> acquired? I tried testing with the attached program and got rather weird
> and (seemingly) non-deterministic results.
>
Threads are by their nature non-deterministic; all ordering must be
implemented manually. Even with a single, ordinary, lock, there are no
guarantees on the order in which waiters are being scheduled upon unlock.

>
> This I do not understand at all. The readers are using the shared mutex.
> Why is the second group waiting for the first to be finished?
>
Probably because the mutex implementation noticed that there have appeared new
writers. This is just a wild guess, I haven't looked at your program. RW
mutex implementation has to be careful not to starve readers nor writers.

>
> And how can the last writer be handled in second place?
>
That's perfectly normal, mutexes are not FIFO.

Now that you've mentioned RW-locks, I remembered a nice article on concurrency:
http://queue.acm.org/detail.cfm?id=1454462


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net