D
David Masover
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?
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.
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?
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.