Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2001-06-21 15:21:09


From: <williamkempf_at_[hidden]>
> ... Beman sugggests ...
> So in my mind, either change the class name to something that denotes
> identifier, handle, or the like, or change the semantics to be more
> thread-like and less thread_id like. Make it noncopyable, and so
> forth. I don't entirely see how to do that. I guess a create_thread
> static or free function could return a pointer to a thread object.
> Then delete of the pointer would kill the thread. But it would have to be
> a weak pointer because the thread might already be dead and thus the
> object already destroyed.
>
> class thread : noncopyable
> {
> // All constructors private, so thread::create()
> // is the only way to create a thread
> thread();
> ...
> public:
> ~thread(); // assert(*this != self())
>
> bool is_alive() const;
> void join();
>
> static thread * create(void (*threadfunc)(void*), void*
> param);
> static thread & self();
> static void join_all();
> static void sleep(const xtime& xt);
> static void yield();
> };

I understand noncopyable, but why force heap allocation via the
create call?

Must constructing a thread automatically start it running? Why
not a separate start() member?

Is the ugly (void (*threadfunc)(void*), void* param) really needed?
Why not (void (*threadfunc) (thread*)), or even a virtual run()
method?

Must destroying a thread object stop thread execution? How? Note
that java was forced to deprecate it's Thread.stop() method in
favor of Thread.interrupt(), which just throws an exception on
the thread.

What is the difference between join() and join_all()? Should they
take an optional timeout?

Is yield() intended to allow non-premptive implementations?


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