[Openmcl-devel] thread pool question

David L. Rager ragerdl at cs.utexas.edu
Thu Jul 13 12:19:29 PDT 2006

Hello Erik,

We have an application that does exactly this, recycle threads.  Well not
formally "recycle", but we prevent the threads from dying and then they grab
more work when it's available.  If you want threads to expire after they've
waited 60 seconds for work, you should consider timed-wait-on-semaphore
instead of wait-on-semaphore.

> > My first attempt at getting this to work relied on preventing the
> > threads from going dead (exhausted) by resetting them just before the
> > thread's function exits (basically the thread runs an anonymous
> > function whose job is to wrap the target function so that it doesn't
> > exit with errors.). I think I found that exhausted threads could
> > sometimes be reused and sometimes not, but the docs say not to do this.

Sounds a complicated.
> > Or perhaps I'm going about this wrong -- the thread could run a
> > function whose job is to just wait (i.e. on a semaphore.) for a
> > function to be provided to it (i.e. setting some variables or slots),
> > then run that function, then when it is done re-enter the wait loop.

> I think that that's what I'd recommend;  PRESET/RESET involve some
> handshaking and synchronization.

I agree with Gary.  This is what we do.  I think you get the benefit of
knowing that each piece of work is large enough to warrant spawning off.
Therefore, you can have a pretty straightforward implementation.  


More information about the Openmcl-devel mailing list