|
Boost : |
From: Matt Hurd (matt.hurd_at_[hidden])
Date: 2005-09-03 09:21:38
> John Maddock wrote:
<snip>
> Cons:
> * If the functor takes a long time to execute, and there are multiple
> threads racing to call-once, then the wait will be less efficient than a
> mutex, this should be a very rare occurance though.
Neat. Though , if f was longer than short, and there was contention,
a lot of wasted cycles could occur.
This leads to the thought that this spinning approach would suffer
from a priority problem if sufficient waiting threads, one on a single
cpu context, were at a higher priority than the initialising item.
This would cause a virtual deadlock, a term I just made up ;-)
pthread32's initial implementation was similar.
Your atomic approach is the right approach I think. A suitable wait
list approach in the "already initializing" section with subsequent
processing after initialisation is complete should cure it and keep
the essence of the fast approach but make it a fair bit more
complicated.
matt.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk