From: Daniel Fort Date: 2009-07-10T13:17:32+09:00 Subject: Re: tcp server with multithreading > Creating a new socketpair/pipe is pretty too much imho (no matter it's a > very > small object, but it exists and must be handled). I thought about some > kind of > semaphore, then process would look like: > > in thread: > > semaphore.wait_for_event > > in main: > > semaphore.emit_event > I've found the way how to do this, here is code + example: #!/usr/bin/ruby -w require 'thread' class MassSemaphoreEmulator def initialize @mutex=Mutex.new # we can have race condition on a variable below, so avoid it with mutex @waiting_threads=[] end def wait @mutex.synchronize { @waiting_threads<