[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
- Re: Why is GNUstep less successful than GTK and Qt??, (continued)
- Message not available
- Re: Why is GNUstep less successful than GTK and Qt??, MJ Ray, 2003/06/14
- Re: Why is GNUstep less successful than GTK and Qt??, Chris B. Vetter, 2003/06/16
- Re: Why is GNUstep less successful than GTK and Qt??, Pascal Bourguignon, 2003/06/16
- Re: Why is GNUstep less successful than GTK and Qt??, Chris B. Vetter, 2003/06/16
- Re: Why is GNUstep less successful than GTK and Qt??, Pascal Bourguignon, 2003/06/16
- Back to the main thread (was: Re: Why is GNUstep less successful than GTK and Qt?? ), Chris B. Vetter, 2003/06/16
- Back to the main thread (was: Re: Why is GNUstep less successful than GTK and Qt?? ), Pascal Bourguignon, 2003/06/16
- Re: Back to the main thread (was: Re: Why is GNUstep less successful than GTK and Qt?? ), Chris B. Vetter, 2003/06/16
- Re: Back to the main thread (was: Re: Why is GNUstep less successful than GTK and Qt?? ), Eric Christopherson, 2003/06/21
- Re: Back to the main thread (was: Re: Why is GNUstep lesssuccessful than GTK and Qt?? ), Adam Fedor, 2003/06/21
- Most elegant solution to Reader/Writer Problem with Objective-C?,
Lachlan Deck <=
Re: Why is GNUstep less successful than GTK and Qt??, Lars Sonchocky-Helldorf, 2003/06/16