"Fukumoto Atsushi" <fukumoto / imasy.or.jp> schrieb im Newsbeitrag news:200303231418.XAA02902 / hawk.wings.imasy.or.jp... > > >> I know there is one in thread.rb that comes with the ruby distrobution > >> but it uses critcal sections, which from reading Pickaxe can be dangerous. > > Uh, you are confusing the problem. Critical sections are nature in > multi-thread programming. In Ruby, Queue class is as much a primitive > tool as Mutex class for inter-thread communication. Rewriting the > Queue class using Mutex gains nothing, and probably it will become > slower. Pardon me, but I like to object that statement: writing a queue class using mutex does indeed gain something. You get increased concurrency. Thread.critical globally prevents all other threads from being executed (with some restrictions for new threads, exceptions etc.), while my implementation using a mutex does not prevent threads from running that do not use the queue. From a more fundamental and maybe theoretical point of view, the mutex is the more appropriate means, because it is focused on queue usage and does not have side effects on other threads running. Thread.critical= OTOH can be seen as acting on a single global mutex which makes immediately clear that it results in less concurrency. Even if that gives better performance I would use the mutex approach as long as there is no need to squeeze out the last bit of performance. > (My experiment showed it's about ten times slower when > written using Mutex. Though some optimization may be possible.) Out of curiosity: did you performance test your own queue implementation or that found on the wiki at http://www.rubygarden.org/ruby?MultiThreading ? And how did you do the tests? Regards robert