Re: Most elegant solution to Reader/Writer Problem with Objective-C?
Re: Most elegant solution to Reader/Writer Problem with Objective-C?
- Subject: Re: Most elegant solution to Reader/Writer Problem with Objective-C?
- From: Greg Titus <email@hidden>
- Date: Wed, 18 Jun 2003 22:29:57 -0700
On Wednesday, June 18, 2003, at 08:56 PM, Lachlan Deck wrote:
I'm doing a presentation for Uni tomorrow and I'm trying to whip up
some examples.
What would be the most elegant solution in Objective-C to solving the
Reader/Writer problem (i.e., allow multiple reader threads to run
concurrently should there be no writer(s); allow at most one writer,
blocking other threads) using, for example the below algorithm?
You could look at our code for this: OFReadWriteLock in OmniFoundation.
As well as doing these:
Readers:
a) concurrent readers activity (i.e., if no writers - go ahead.
Incrementing/Decrementing count on entering and exiting of sections).
b) if (waiting writers) new readers join a new queue instance that
corresponds to a single writer in the queue.
Writers:
c) at most one writer activity exclusive of any other threads (i.e.,
if no readers or writers - go ahead).
d) if active readers or active writer, this writer is placed as the
key at the end of the queue (with any subsequent readers entering
joining the list associated with this writer) and awakes when it is
the at the head of the queue and there are no active readers. When it
finishes, the waiting readers associated with it in the queue are
signalled to proceed (when they finish the next writer goes and so we
go on...)
It also:
a) Allows recursive locking by each thread,
b) Detects and corrects deadlocks caused by the same thread attempting
a write lock when it already holds a read lock,
c) Orders the granting of the write lock to guarantee there is no
starvation.
It does not support atomic upgrade of read to write locks, however.
See: <
http://www.omnigroup.com/developer/sourcecode/>
Hope this helps,
- Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.