Monday, February 18, 2008

Perl threads :-(

I chucked in an entry for the Computer languages shootout game for the Perl implementation of a thread-ring. I've a few observations:
  1. My application relies on semaphores that unblock themselves quickly. On average, there's two threads running (rather than blocking on a semaphore) at a time, but my dual core PC is only 60-80% utilised. Something in the cond_wait implementation is sleeping.
  2. Try as I might, semaphores were the only IPC mechanism I could get to work in a way that appeared "correct" (rather than spurious errors about shared or locked, or whatever). This may be a reflection on the workman rather than his tools.
  3. Getting any cross-platform, efficient, thread-safe, IPC across muliple versions of Perl, is like pulling teeth. I've got a blended semaphore-based implementation ready to go. By blended, I mean it uses (inefficient) semaphores for the tricky first lap around the ring (ensuring that all initialisation is done correctly), and then move over to "something" immediate for message passing. I need a working message passing implementation to slot in now.
  4. As the shootout game demonstrates, Perl threads are not even close to universally available in any sense of the term.
My entry: http://shootout.alioth.debian.org/gp4/benchmark.php?test=threadring&lang=perl&id=0

I'm going to see if libevent holds any hope for me. If not, then maybe a mass of file handles, and select statements...

No comments: