|
Boost : |
From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2006-10-30 12:45:19
Chris Thomasson wrote:
> // usage...
> static atomic::once<foo> g_foo;
>
>
> void some_threads(...) {
> for(;;) {
> // whatever...
>
>
> foo *myfoo = g_foo.load();
> }
> }
>
> Any thoughts?
>
This looks similar in usage to me as my proposal of
"thread safe initialization of local static and global objects"
in
http://lists.boost.org/Archives/boost/2006/10/111221.php
In this discussion we came to the conclusion that the problem
with this scheme is not the construction, but the destruction.
When will the destructor of this object being run?
The object is kind of split brain: On the one hand it is a
dynamic object that lives on the heap, on the other the
programmer thinks of the object as being static.
This obviously affects live-time very differently.
(In the discussion we recognized this because we were not
able to tell when the atexit handler should destroy te object.)
This is why I abandoned the idea, because using a statically
initializeable mutex is a much more natural thing to comprehend
for the programmer.
void bar
{
static mutex;
lock lk(mutex);
static myclass m(42);
lk.unlock();
}
I glanced over your code snippet and saw that you have a dtor
in once. Unfortunately the comment "assume this is statically
out of scope" does sound very cryptic to me.
Would it be possible for you to try to explain which problem
exactly your code tries to solve, and how?
Thank you
Roland
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk