discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Most elegant solution to Reader/Writer Problem with Objective-C?


From: Lachlan Deck
Subject: Most elegant solution to Reader/Writer Problem with Objective-C?
Date: Thu, 19 Jun 2003 13:54:35 +1000

Hi all,

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?

Thanks very much!

Any examples would be great, but one which does the following would be even better:

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...)

So we have the following,
- A count of active readers
- A bool for an active writer
- A queue that maintains a list of waiting threads where:
+ Each entry in the queue represents a waiting writer (so the queue count is the waiting writer count (less 1 if activeWriter is true)) + Each writer in the queue is associated (or mapped) with a list of waiting readers. i.e., as each readers 'enters', if there are waiting writers, it is added to a list with other waiting readers (associated with the last waiting writer in the queue).

Thanks muchly.

with regards,

--
Lachlan Deck
ldeck@tpg.com.au





reply via email to

[Prev in Thread] Current Thread [Next in Thread]