[cpp-threads] Fixing the thread type
Peter Dimov
pdimov at mmltd.net
Tue Nov 15 11:14:27 GMT 2005
Ben Hutchings wrote:
> As you may know, Pete Becker proposed standardisation of the
> Boost.Thread library in N1907. I know Andrei Alexandrescu has some
> serious objections to this library and Kevlin Henney has a much richer
> thread library in mind. However, in the absence of a concrete proposal
> from them or a larger group of us (and, I would imagine, implementation
> experience) it seems likely to me that something like Boost.Thread will
> be standardised. Therefore I would like to propose, as a fallback, some
> cleaning up of the interface described in N1907. Here's my first draft:
> <http://womble.decadentplace.org.uk/c++/std-thread-fix.html>.
For reference:
class thread
{
public:
thread();
template <class Func>
explicit thread(Func func);
bool operator== (const thread& other) const;
bool operator!= (const thread& other) const
{return !operator==(other); }
bool is_current () const;
void join();
static void sleep(const xtime& xt);
static void yield();
// exposition only
private:
// not implemented
thread(const thread&);
thread& operator= (const thread&);
};
My counterproposal is:
// everything in namespace std::tr2
class thread_handle;
// thread_handle is CopyConstructible, EqualityComparable,
LessThanComparable,
// OutputStreamable (for logging/debugging)
// DefaultConstructible? TBD
template<class F> thread_handle create_thread( F f );
thread_handle current_thread();
void join_thread( thread_handle const & th );
bool try_join_thread( thread_handle const & th );
bool timed_join_thread( thread_handle const & th, xtime const & xt );
// void cancel_thread( thread_handle const & th ); // maybe one day
Substitute thread_/_thread with namespace thread:: according to taste. :-)
More information about the cpp-threads
mailing list