|
Boost : |
From: Alexander Terekhov (terekhov_at_[hidden])
Date: 2003-05-26 08:02:45
Edward Diener wrote:
>
> Alexander Terekhov wrote:
> > Hardcore POSIX folks don't really "think C++", unfortunately. The only
> > way to get it done is to deliver POSIX threading API implementation
> > "on
> > top" of Boost.Threads to them, I think. Well, this would also mean a
> > whole bunch of extensions to the current POSIX threading -- things
> > like parameterized pthread_once() and TSD destructors (to support
> > shared_ptr
> > like "custom deleters" without too much overhead), etcetera.
> >
> > What do you think?
>
> What I think is that it is about time that C++ stop trying to accomodate the
> C programming language in any respect, and develop itself using C++ idioms
> and ideas even if it means leaving the C language completely behind.
I don't understand.
What's the problem with respect to "additional" C interface to the
pure C++ stuff with whatever-C++-"idioms and ideas"-you-like? You
just hate void *, or what? If you hate it, don't use it.
I think that you've missed the point. The "extensions" I was talking
about can be illustrated on thread_specific_ptr (current boost::once
ugliness aside for a moment). As far as I can see, efficient support
[without considerable overhead] for the C++ style deleters needs the
system support for a TSD destructor callback that would allow to have
something along the lines of "dtor" below:
template<typename T, typename cleanup>
class thread_specific_ptr : cleanup /*, noncopyable */ {
...
static void dtor(void * data, void * THIS) {
static_cast<thread_specific_ptr*>(THIS)->operator()(static_cast<T*>(data));
}
...
};
as the TSD destructor. Basically you need the following pthread
"extension"
extern "C++" int pthread_key_create(pthread_key_t *,
void (* dtor)(void *, void *),
void * state) throw();
it doesn't need to be a "pthread" call. The system could provide
extern "C++" int __tsd_key_create(__tsd_key_t *,
void (* dtor)(void *, void *),
void * state) throw();
(or whatever)
and once you have THAT (plus primitive get/set operations), you can
implement a C++ thread_specific_ptr<T, cleanup> template with e.g.:
thread_specific_ptr();
thread_specific_ptr(const cleanup&);
~thread_specific_ptr() throw();
T * get() const throw();
void set(T *) throw(std::bad_alloc);
T * operator->() const throw();
T * release() throw();
void dispose() throw();
void reset(T *) throw(std::bad_alloc);
and layer the entire pthread TSD C-API "on top" of it (with
_release(), _dispose(), and _reset() calls also added as "extensions").
What's the problem?
> This is
> what Boost is currently doing and I see attempts to accomodate C as
> crippling the vitality of C++ and blocking the attempt to create a more
> dynamic C++ language for the future.
regards,
alexander.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk