Michael Maged
Kevlin Henney
kevlin at curbralan.com
Tue Oct 5 14:44:41 BST 2004
In message <41603C42.20801 at metalanguage.com>, Andrei Alexandrescu
<andrei at metalanguage.com> writes
>
>> Good question. The dead minimum for (1) seems to be to define a Thread
>> class, with ways to create, start, block, unblock, block-with-timeout,
>> detect termination, and query status. You could then in principle
>> build everything in (2), not that most people would want to --
>> existing stuff must be able to comply. Can this be done in a way that
>> everyone is guaranteed to love, or at least tolerate?
>
>I believe so. The way that I think would be most natural to the C++
>community would be to have a start_thread template function that takes
>a generic functor and returns a Thread object. The Thread object ought
>to be parameterized by the type returned by the functor. This way users
>can call query_result(). Here's a sketch:
>
>template <class Result>
>class thread {
> ...
>public:
> void block();
> void block(unsigned int timeout);
> void unblock();
> Result query_result();
> Result force_result();
> ...
>};
>
>template <class Result, class Fun>
>thread<Result> start_thread(Fun fun) {
> ...
>}
>
>A note - there are facilities in C++'s current standard library that
>allow you to pack a pointer to object and a pointer to member function
>in one functor. So starting a thread via a functor works with simple
>functions as well as with member functions.
My inclination is towards a slightly more decoupled model, taking the
function metaphor further. See attached PDF as an example.
Kevlin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: More C++ Threading.pdf
Type: application/octet-stream
Size: 426246 bytes
Desc: More C++ Threading.pdf
Url : http://shadbolt.decadentplace.org.uk/pipermail/cpp-threads/attachments/20041005/5f2540b3/MoreCThreading.obj
-------------- next part --------------
--
____________________________________________________________
Kevlin Henney phone: +44 117 942 2990
mailto:kevlin at curbralan.com mobile: +44 7801 073 508
http://www.curbralan.com fax: +44 870 052 2289
Curbralan: Consultancy + Training + Development + Review
____________________________________________________________
More information about the cpp-threads
mailing list