From: MenTaLguY Date: 2008-02-21T07:44:46+09:00 Subject: Re: Ruby 1.9, threads and FreeBSD 5 On Thu, 21 Feb 2008 06:51:18 +0900, Eric Jacoboni wrote: > I've had wrote a general semaphore implementation using IO.pipe That can still be useful sometimes -- for example, I wrote a concurrent-selectable gem which provides latch, semaphore, and channel (queue) implementations which can be passed as arguments to IO.select, libev, etc. because they use IO.pipe underneath. > PortableSemaphore is way more elegant... thanks a lot (i just wonder > if #up/#down honor the FIFO policy) It depends upon the implementation of ConditionVariable#wait. Some Ruby implementations will wake threads in the order the threads called #wait, and some will not. Most are roughly FIFO but not 100% "fair". Fairness actually involves a tradeoff: while unfair blocking primitives can sometimes lead to starvation (as sufficiently greedy threads could keep "jumping the queue"), fair primitives are more likely to have problems with convoying[1]. -mental [1] Google "lock convoying"