Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2001-10-11 12:37:12


on 10/11/01 10:29 AM, Darin Adler at darin_at_[hidden] wrote:

> on 10/11/01 10:27 AM, helmut.zeisel_at_[hidden] wrote:
>
>> 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.
>
> Oops. My mistake.

I just realized we don't need to put the thing into a struct. We can just
pass &func to pthread_setspecific and do:

    static void do_once()
    {
        once_callback* cb = static_cast
            <once_callback*>(pthread_getspecific(key));
        (**cb)();
    }

Because a pointer to a function is an object, so a pointer to a pointer to a
function is a pointer to an object :-)

My apologies for spending so much list bandwidth on this minor coding issue.

    -- Darin


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