Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2007-09-21 09:04:05


Anthony Williams wrote:
> Tobias Schwinger <tschwinger_at_[hidden]> writes:
>
>> Anthony,
>>
>> Anthony Williams wrote:
>>> POSIX provides pthread_once. We should use it. The Windows Vista functions
>>> look to supply a similar facility, and do at least allow the passing of a
>>> parameter to the routine without using TSS.
>> did you catch my comments on this one (elsewhere in this thread)?
>
> No. Thanks for repeating them here.
>
>> <cite>
>> The pthread-based implementation seems overly simplified: It won't
>> compile for C++ functions that are not 'extern "C"' with some
>> compilers.
>> Further, what about exceptions from within pthread_once?
>> </cite>
>
> I haven't written a pthread-based implementation yet, so I'm not sure what
> you're referring to.

I see. I was referring to the one in the thread_rewrite branch, which is
basically just pthread_once. Well, I should've tripped over the
interface differences, though :-)...

> Current boost call_once is not header-only, and doesn't
> support arbitrary callable objects (like my new Windows version does) --- only
> functions of a fixed signature.
>
>> I agree that TSS is not a good alternative, however (but I don't think
>> it's needed for an improved pthread-based implementation).
>
> I'm interested in what you expect an improved pthread-based implementation to
> look like. I'm thinking it will look very much like Peter's extended
> pthread_once that took an additional parameter (from N2178) --- i.e. using TSS
> to pass the parameter to the routine passed to pthread_once, which can then
> use this parameter data to invoke the user-supplied callable object. Have you
> got a better way?

For someone implementing pthread? Sure, just use the stack.

For someone implementing a standard runtime? A piece of assembler (or a
tricky cast construct) to pick that value from the caller's stack plus
some means to keep the compiler from messing it up will most probably
do. (Not considering exception propagation as it seems to me it can be
implemented on top of it).

For us trying to implement a nicer 'call_once' in a portable way? We
probably should not be using 'pthread_once' and just do basically the
same thing as on Windows (using an aggregate-initialized mutex instead
of a named one).

Regards,
Tobias


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