From: MenTaLguY Date: 2008-03-26T09:06:02+09:00 Subject: Re: thread.rb On Wed, 26 Mar 2008 07:32:27 +0900, "Adam Bender" wrote: > I couldn't find the Scheduler gem gem install scheduler > I didn't understand the point of the Reader class in your code, since > only one thread at a time can acquire the lock in pop. The lock is released (by ConditionVariable#wait) while a reader is waiting (and re-acquired before ConditionVariable#wait returns). Otherwise writers couldn't get in to write. Conceptually, a Queue is actually two queues: a queue of "pushes" which holds pushed values, and a queue of "pops" which holds threads waiting for new values to be pushed. If there have been more pushes than pops, the "pushes" queue will have entries in it, and if there have been more pops than pushes, the "pops" queue will have entries in it. Each push tries to take an entry from the "pops" queue and vice-versa, so that when there have been an equal number of pushes and pops, both queues will be empty. Readers are just used to represent entries in the "pops" queue. -mental