From: "Thomas B." Date: 2008-09-22T19:14:24+09:00 Subject: Re: ThreadError: not owner Caleb Clausen wrote: > On 9/22/08, Thomas B. wrote: >> Thanks for your responses. >> [snip] >> Unfortunately, Monitor does not allow this way of usage, too. > > Really? After I looked into it, it seemed like maybe you could use a > condition variable, but then I've never understood monitors or > condition variables properly. A semaphore seems so much simpler, for > this case, at any rate. I guess condition variables would have the > advantage of being faster, (if they can be made to work) since they > were presumably rendered into c as well. As far as I know, the only difference between Mutex and Monitor in Ruby (apart from the internal implementation, I mean) is that Monitors are reentrant, meaning that a monitor can not only be locked or unlocked, but it can also be locked multiple times, if all the locks come from the same thread, so you can do this: mon.synchronize{mon.synchronize{x}} and get no deadlock or anything. But still it has to be unlocked by the same thread that locked it. As for condition variables, I don't think they could help in my situation. It's not what they are designed for, if I understand them well. I think that the Semaphore (or maybe I'll write my own Semaphore class) is the best solution here, only I hoped for a core class for doing this. -- Posted via http://www.ruby-forum.com/.