
Alexander Terekhov <terekhov@web.de> writes:
Anthony Williams wrote: [...]
I can understand what you're getting at with the derived class for dynamic contexts, such as class members, but how are you envisioning the call_once_reset function working? Would it take a specific once_flag as a parameter, and reset it, as if it has never been called?
Yes. And also cleanup result stuff, if any. Pretty much the same notion (reset() vs destroy() aside for moment) as with statically initialized pthread primitives and corresponding _destroy() calls like pthread_mutex_destroy() that can be used for "pedantic" cleanup of statically initialized pthread objects at process termination to please leak detectors (resources may be acquired dynamically on first use) or whatnot.
Makes sense.
When would this be used,
That's up to the client. For example, in some module_fini().
and how would it help with static destruction?
Static destruction of what?
Destruction of once_flags with static storage duration. If we store the return value along with the once_flag, then we really ought to destroy it properly, when the once_flag is destroyed. If a once_flag has static storage duration, and has a non-trivial destructor that does cleanup, then we have a classic singleton cleanup problem, as John Maddock pointed out --- the order of static destruction can now be important. Anthony -- Anthony Williams Software Developer Just Software Solutions Ltd http://www.justsoftwaresolutions.co.uk