• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Most elegant solution to Reader/Writer Problem with Objective-C?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Most elegant solution to Reader/Writer Problem with Objective-C?
  • From: Lachlan Deck <email@hidden>
  • Date: Thu, 19 Jun 2003 13:56:55 +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: (or if there's a better algorithm that would be great too)...

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
email@hidden
_______________________________________________
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.

  • Follow-Ups:
    • Re: Most elegant solution to Reader/Writer Problem with Objective-C?
      • From: Daryn <email@hidden>
    • Re: Most elegant solution to Reader/Writer Problem with Objective-C?
      • From: Greg Titus <email@hidden>
  • Prev by Date: dummy question about Rendezvous
  • Next by Date: Use libcddb in my Cocoa App
  • Previous by thread: Re: dummy question about Rendezvous
  • Next by thread: Re: Most elegant solution to Reader/Writer Problem with Objective-C?
  • Index(es):
    • Date
    • Thread