From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2005-09-13 11:00:09
Jason Hise <chaos_at_[hidden]> writes:
> John Maddock wrote:
>>The mutex is unique to both the calling process and the call_once flag, but
>>not the function pointer (however there should always be a one to one
>>correspondence between the once-flag and the function pointer).
> I should probably elaborate on my problem a little bit more. I wanted
> to create a function that makes a given call atomic, but doesn't enforce
> that the function be called only once. I thought I could do so by using
> a once_flag allocated on the stack immediately before invoking
> call_once, so the flag would always be reinitialized to BOOST_ONCE_INIT
> and call_once could just offer me it's atomic guarantees, but apparently
> that won't work. I guess I'll just have to find some place to put my
> own mutex where it can be constructed safely.
Calls through call_once are only atomic with respect to other calls that
reference the same once_flag. If you want mutual exclusion, you need a shared
mutex --- why not just create a function-local static mutex, lock it before
your function call, and unlock it afterwards?
-- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk