From: Robert Klemme Date: 2012-05-16T16:27:39+09:00 Subject: Re: How to ensure that a block runs entirely after other threads? (Thread.exclusive does not "work") On Tue, May 15, 2012 at 5:36 PM, Iņaki Baz Castillo 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/