From: Yohanes Santoso Date: 2002-04-01T15:29:30+09:00 Subject: Re: Multithreaded socket code. Request for Comments Matt Armstrong writes: > "Robert C. Martin" writes: > > > @lock.synchronize {@threads << Thread.current} > > @lock.synchronize {@threads.delete(Thread.current)} > > @lock.synchronize {threads = @threads.dup} > > I don't think you need to synchronize these operations. For the first > two, the value returned by Thread.current won't become invalid no > matter what other threads do. And I am 90% sure that Array.delete, > Array.<< and Array.dup are all atomic in Ruby's thread model. I found out the hard way that Array operations are not atomic. So, the OP needs to synchronise. On another front, shouldn't @threads be @@threads (class variable). Otherwise, the following will have the wrong concept: s1 = SockService.new s2 = SockService.new s1.serve 119 {handle_nntp} s2.serve 119 {handle_nntp} #will be allowed YS.