Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2007-03-22 13:22:20


"Peter Dimov" <pdimov_at_[hidden]> writes:

> Anthony Williams wrote:
>
>> OK. But that doesn't really address my initial point: implementing
>> call_once in terms of the POSIX pthread_once is a bit pointless if
>> you need to implement pthread_once separately anyway. If you don't
>> have pthread_once, I would write call_once (or, equivalently
>> pthread_once2_np), and implement pthread_once in terms of that.
>
> This is tied to another issue, whether the implementation should be
> header-only. If one is committed to produce a header-only implementation, it
> makes sense to reuse your current call_once in the implementation of
> pthread_once (and possibly pthread_once2_np).

I really don't get why that matters for this issue.

> The N2178 pthread.h aims to support the scenario where one is to deliver a
> separately compiled pthread-win32.lib/dll (as part of the Platform SDK, say
> ;-) ). This is why I've tried to make sure that the C++ templated layer is
> implementable without loss of performance or generality in terms of a
> non-templated API (which happens to be a slightly extended pthreads layer).
> With careful definitions of the pthread_* types, it's possible to achieve
> binary compatibility as well, that is, link the program against a newer
> version of pthread-win32.lib/dll and have it work without recompilation.
> This is not possible with header-only templates or inline functions, because
> they are burned into the application code at compile time.

If you define a C API, and people stick to it, then it doesn't matter what you
use internally: you can ship a .LIB file or .DLL with just that API exposed,
and Bob's your uncle. If you want to use a templated API, you just can. You
can even provide the necessary specializations of the templates as part of the
library, and declare them as explicit specializations in the headers.

If the templated API changes, then you need to recompile the app to take
advantage of that, anyway.

Anthony

-- 
Anthony Williams
Just Software Solutions Ltd - http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

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