From: Thomas Sondergaard Date: 2003-09-18T09:32:21+09:00 Subject: Thread safety: Serializing access to ruby interpreter- again I recently asked about this and got answers, but here I go again: How can I efficiently serialize access to the ruby interpreter. I have to make sure all access to the ruby interpreter happens on a particular thread (not a ruby thread, mind you), so when a different thread attempts to access the ruby interpreter I need it to have it post the job to a queue and then wait for a ruby worker thread on the ruby-thread (:-)) to execute whatever it needs done. Btw, in this mail I use the term ruby-thread, with a dash in the middle, as a reference to the heavy-weight thread in which the ruby interpreter executes. The thing is that if I have a ruby thread on the ruby-thread block on a heavyweight thread lock the entire ruby-thread is blocked. This is demonstrated by this bit below (which requires my dotnet module to work). It simply starts a thread that writes to the console continuously and then the main thread waits for a signal on anObject. However that wait() call blocks the entire ruby-thread not just the "green" ruby main thread, so I never get to see a steady stream of hello worlds, and that is what ruins my day. require 'dotnet' t = Thread.new { while true; sleep 0.1; puts "hello world"; end } anObject = System::EventArgs.new System::Threading::Monitor.enter(anObject) System::Threading::Monitor.wait(anObject) # This blocks the entire ruby-thread System::Threading::Monitor.exit(anObject) t.join So if I am not allowed to touch the ruby interpreter from other threads than the ruby-thread how can I wake up a sleeping worker thread when there is something for it to do? Is there a heavyweight-thread-safe way to wake up a ruby thread? Shouldn't there be? - Thomas