Boost logo

Boost :

From: helmut.zeisel_at_[hidden]
Date: 2001-10-11 12:27:11


--- In boost_at_y..., Darin Adler <darin_at_b...> wrote:
> >> @@ -38,7 +41,7 @@
> >>
> >> static void do_once()
> >> {
> >> - once_callback cb =
> >> reinterpret_cast<once_callback>(pthread_getspecific(key)
> >> );
> >> + once_callback cb =
> >> reinterpret_cast<once_callback_wrapper*>(pthread_getspec
> >> ific(key))->cb;
> >> (*cb)();
>
> This should be:
>
> static void do_once()
> {
> once_callback_wrapper* wrapper =
static_cast<once_callback_wrapper*>
> (pthread_getspecific(key));
> (*wrapper->cb)();
> delete wrapper;
> }
>
> We need to delete the wrapper,

IMHO, no.
At least my test program crashes wenn I delete the wrapper.
Observe that the wrapper has not been allocated
dynamically:

once_callback_wrapper w;
w.cb=func;
pthread_setspecific(key, &w);
pthread_once(&flag, do_once);

it is destroyed automatic and is indeed not needed
when pthread_once has finished.

"On return from pthread_once(), it is
guaranteed that init_routine() has completed.", cf.
http://www.unix-systems.org/single_unix_specification_v2/xsh/pthread_once.html

> and there's no need to resort to
> reinterpret_cast.

OK; static cast is better.

Helmut


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk