From: Robert Klemme Date: 2008-09-11T15:33:25+09:00 Subject: Re: How to detect blocking? On 11.09.2008 06:48, David Masover wrote: > I've been (barely, occasionally) writing an Actor system for Ruby. > > It was actually pretty easy, when I was doing one thread per actor, but that > has some serious drawbacks -- among them that threads can't be garbage > collected (can they?), whereas actors really should be collectable. > > So now I'm considering running a smaller number of threads -- at least one per > usable CPU (so at least one on mainline Ruby, more on JRuby) -- but more, > since operations might block. > > The problem is, how do I detect a blocked thread, and execute some code when > that happens? Block on what? IO? In that case you probably want to use more threads as Ruby does handle this nicely. > The best I can think of is to poll, checking for #stop?, but that's hackish, > and performance would be awful. Poll too often, and I burn CPU -- not often > enough, and I end up with large windows of my app waiting for the poll thread > to wake up. I do not have a clear idea of your app but usually with multiple threads you use some form of synchronization (blocking queues, condition variables etc.). HTH Kind regards robert