Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-07-01 09:32:57


From: "Greg Colvin" <gcolvin_at_[hidden]>

> > A design with
> >
> > thread::ref thread::create(void (*) (void *), void *);
> >
> > plus the corresponding helpers for managing the parameter passing and
> > dealing with different function signatures still has the properties
outlined
> > above.
> >
> > A design that takes boost::function0<void>, sadly, does not, as far as I
can
> > see. Someone has to manage the function object, and the logical place to
put
> > it is in the noncopyable thread.
>
> One could just copy it around as part of the ref object.

Nicht gut, as boost::function uses clone on copy. But I have a solution now:

We have this:

thread::ref thread::create(void (*) (void *), void *);

and we want this:

template<class F> thread::ref thread::create(F f);

Here's how:

template<class F> void _f(void * f)
{
    std::auto_ptr<F> p(static_cast<F *>(f));
    (*p)();
}

template<class F> thread::ref thread::create(F f)
{
    create(&_f<F>, new F(f));
}

--
Peter Dimov
Multi Media Ltd.

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