[cpp-threads] Thread try/time_join (was: Asynchronous FunctionProposal)
vicente.botet
vicente.botet at wanadoo.fr
Wed Jun 3 07:59:12 BST 2009
----- Original Message -----
From: "Herb Sutter" <hsutter at microsoft.com>
To: "C++ threads standardisation" <cpp-threads at decadentplace.org.uk>
Sent: Wednesday, June 03, 2009 12:08 AM
Subject: [cpp-threads] Thread try/time_join (was: Asynchronous FunctionProposal)
>
> [forking the subject line]
>
>> > Could someone please refresh my memory as to why try_join and
>> > timed_join were not included? Was it a lack of motivating use cases?
>>
>> For my money it is because of lack of those functions in the posix
>> API. I.e. I'd like to layer std::thread as thinly as possible over
>> what my OS offers, which is pthreads. Adding try/time_join into
>> higher level layers (such as future) doesn't bother me at all because
>> one is already into thicker layers (auxiliary heap storage) by then.
>
> Are you opposed to adding a couple of functions to thread that aren't in every threading API? Just because it's not part of core pthreads doesn't mean we shouldn't fill a gap and provide a complete interface, right? (I promise not to mention the C-word here.)
>
> Peter, if this is important, is someone writing an issue about it?
Hi,
In Boost.Async I have implemented the threader/joiner framework proposed by Kevlin Henney. A Threader can be seen as a Joiner factory executing asynchronously a function on a thread encapsulated on the returned Joiner. The joiner is used to synchronize with and pick up the result from a function using a future or to manage the encapsulated thread. Even if std::thread do not implement try_join/timed_join, the joiner allows to emulate them using the future interface. In the Boost.Async terminology the threader class is a model of an AsynchronousExecutor and the Joiner is a model of an AsynchronousCompletionHandler. The fork(async) function is used as follows:
threader thr;
auto act = fork(thr, f , p1, pn);
fork is a template function returning a handle providing the future<result_type> interface. The result type of fork depends on the asynchronous executor.
BTW, std::thread do not have a get() function and nobody complains. IMO try_join/timed_join should be provided by std::thread if this means that we need to add some kind of synchronization like a future in the thread implementation.
HTH,
Vicente
More information about the cpp-threads
mailing list