On 2/15/10, Robert Klemme <shortcutter / googlemail.com> wrote:
> 2010/2/15 Mido Peace <mido.peace / gmail.com>:
>>     @sem=Semaphore.new(0)
>
> IIRC semaphores are typically initialized with a positive value, i.e.
> something larger than 0.  If you think about it, init with 0 does not
> make too much sense.

It depends on what you're using the semaphore for. If it's to be used
for locking, you're right. If it's a signaling semaphore, then 0 for
the init value is exactly what's needed.

Mido, what do you want this for? Mutual exclusion? (But then why not
just use a Mutex?) Signaling? Counting semaphore?

You might consider using a (sigh) Queue or SizedQueue instead. Even
tho it's kinda silly to use a Queue when all you're ever putting on or
taking off the queue is instances of TrueClass.

It used to be possible to fake signaling semaphore behavior by
creating a Mutex then immediately locking it. That doesn't work
anymore, tho; the thread that unlocks a Mutex now has to be the same
one that locked it.