Boost logo

Boost :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2006-10-08 10:53:15

Anthony Williams wrote:
> Roland Schwarz <roland.schwarz_at_[hidden]> writes:
>> class once_init does have a user declared constructor and a destructor!
>> And this definitely is _not_thread safe.
> Yes, agreed. That's why the operator-> also does a lazy_init().
> This is completely platform- and implementation-dependent code, precisely the
> sort of thing that needs to be wrapped in a library, and not written by the
> general public.

I am not convinced yet, that this code is thread safe even on MSVC:
You can happen to have multiple ctor calls waiting on
in init_once, true?

Then when the the event is signalled (after the object has been
constructed) all pending ctors (possibly just having waited)
return. Now if you look at the assembly code level, you will
see that each will schedule a call to atexit, which makes your
code end up with multiple calls to dtor. This is bad. isn't it?
(Not to mention, that I think I found out that the call to atexit
itself isn't thread safe :-(, at least for posix, don't know
for MSVC yet.)

> On MSVC 7.1, the compiler will call the constructor in the first thread that
> starts the function, and not any others.

Sorry I cannot see this. Why wouldn't the others beeing called while
construction is underways?


Boost list run by bdawes at, gregod at, cpdaniel at, john at