RE: [boost] Critique of Boost.Threads

-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Beman Dawes Sent: Wednesday, May 04, 2005 6:31 AM To: Boost mailing list Subject: [boost] Critique of Boost.Threads
With Kevlin Henney's permission, the following is a repost of a message he recently posted on the C++ committee's library reflector. It gives his views on Boost.Threads in the context of possible standardization.
--Beman
-------
I have a (newbie) question about the joiner API.
And usage as follows:
void void_task(); int int_task(); ... joiner<void> wait_for_completion = thread(void_task); joiner<int> wait_for_value = thread(int_task); ... int result = wait_for_value(); wait_for_completion();
In the code snippet above does the line "int result = wait_for_value();" block until the completion of the thread? (It must or there is no way of knowing if the value of result is valid.) Is there a way for the client to avoid the block by checking whether or not thread is completed so that the call won't block... Some sort of wait_for_value.is_done()? -- Jon Kalb jonkalb@microsoft.com

Jon Kalb wrote:
In the code snippet above does the line "int result = wait_for_value();" block until the completion of the thread? (It must or there is no way of knowing if the value of result is valid.) Is there a way for the client to avoid the block by checking whether or not thread is completed so that the call won't block... Some sort of wait_for_value.is_done()?
I would hope the joiner class has a non-blocking check. IIRC, ACE does allow you to check in a non-blocking fashion with its future objects Cheers Russell

In message <435B34B617D19D40977CBB72A9C3463804CFF8F2@RED-MSG-53.redmond.corp.microso ft.com>, Jon Kalb <jonkalb@microsoft.com> writes
And usage as follows:
void void_task(); int int_task(); ... joiner<void> wait_for_completion = thread(void_task); joiner<int> wait_for_value = thread(int_task); ... int result = wait_for_value(); wait_for_completion();
In the code snippet above does the line "int result = wait_for_value();" block until the completion of the thread? (It must or there is no way of knowing if the value of result is valid.) Is there a way for the client to avoid the block by checking whether or not thread is completed so that the call won't block... Some sort of wait_for_value.is_done()?
Yes, the simple check to allow non-blocking behaviour is expressed as a Boolean conversion, ie if(wait_for_value) { int result = wait_for_value(); ... // do something with result now thread has completed } else { ... // do something else instead } This ability to query availability is a typical feature of future variables. Kevlin -- ____________________________________________________________ Kevlin Henney phone: +44 117 942 2990 mailto:kevlin@curbralan.com mobile: +44 7801 073 508 http://www.curbralan.com fax: +44 870 052 2289 Curbralan: Consultancy + Training + Development + Review ____________________________________________________________
participants (3)
-
Jon Kalb
-
Kevlin Henney
-
Russell Hind