From: Robert Klemme Date: 2007-10-14T03:15:02+09:00 Subject: Re: Is there a standard pattern for threaded access to a file? On 13.10.2007 17:52, Simon Kröger wrote: > Eric I. schrieb: >> That's a very nice solution. It demonstrates a lot of accumulatd >> wisdom. I think I'd use a symbol in the queue, such as :end_of_data, >> rather than the queue itself to mark the end of the data, if only to >> avoid a "huh?" moment from those who read the code down the line. > > I think there will be a big (and probably long) "huh?" moment when running the > code: > > threads.each do |th| > # send the terminator and wait > queue.enq queue > th.join > end > > is more likely than not to never terminate. If another thread than th is eating > the terminator th.join will wait for a long time. Of course you are right! Normally I use two loops here - dunno why I suddenly though this was a great idea. Thanks for catching that stupid error! I also agree to Eric, that using something else is probably better because the code will be more readable. I just wanted to demonstrate the point to not use a "regular" queue element. Kind regards robert