On Tue, May 15, 2012 at 5:36 PM, Iñaki Baz Castillo <[email protected]> wrote: > Hi, I expected that in the following example code, thread t1 would not > work until the Thread.exclusive blocks ends, but I am wrong: > > -------------------------------------- > t1 = Thread.new { loop do printf "." ; sleep 0.1 end } > > Thread.exclusive do > puts "entering Thread.exclusive..." > sleep 2 > puts "exiting Thread.exclusive" > end > > t1.join > -------------------------------------- > > > But thread t1 runs every 0.1 seconds so I've don't properly understood > the doc about Thread.exclusive. So, is there any easy way for telling > Ruby "run this block entirely without passing the GVL to other thread > in the middle of the block"?
Do I understand that correctly that you want to have 1 thread run exclusively in the interpreter? If that's the case I agree with Eric: that's a bad idea. You only need to synchronize access to shared resources. If there are threads which do not access the shared resource there is no point in blocking them. I do not know your sharing and exclusiveness requirements but one helpful option might be a read write lock. Or, of course, a regular mutex. In any case you need to define in code which threads share which resources and hence require exclusive access. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
