[thread] condition::try_wait() and thread::try_join()?

Hi Anthony, I'm sure there you have a good rationale to don't have condition::try_wait() or thread::try_join() functions. Could you share with us? Can these functions be emulated? If yes, why not adding them? Best, Vicente

I'm sure there you have a good rationale to don't have condition::try_wait() or thread::try_join() functions. Could you share with us? Can these functions be emulated? If yes, why not adding them?
AFAIK -pthreads do not support try_wait() for condition variables etc. Oliver -- "Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ... Jetzt GMX ProMail testen: http://www.gmx.net/de/go/promail

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
I'm sure there you have a good rationale to don't have condition::try_wait() or thread::try_join() functions. Could you share with us? Can these functions be emulated? If yes, why not adding them?
What would try_wait do? A condition variable notify only applies to currently waiting threads. Since "try_wait" would be instantaneous, it would never be notified since you would never get a concurrent call to notify. You have timed_wait though, so you could try it out with a timeout of zero if you're so inclined. try_join is more sensible, and it might be worth adding it. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, November 10, 2008 12:57 PM Subject: Re: [boost] [thread] condition::try_wait() and thread::try_join()?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
I'm sure there you have a good rationale to don't have condition::try_wait() or thread::try_join() functions. Could you share with us? Can these functions be emulated? If yes, why not adding them?
What would try_wait do? A condition variable notify only applies to currently waiting threads. Since "try_wait" would be instantaneous, it would never be notified since you would never get a concurrent call to notify. You have timed_wait though, so you could try it out with a timeout of zero if you're so inclined.
Ok, I see.
try_join is more sensible, and it might be worth adding it.
I'm more interested on the try_join. Does the following do a try_join? boost::thread th(fct); th.timed_join(0); Is this the more efficient way? Thanks, Vicente

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
From: "Anthony Williams" <anthony.ajw@gmail.com>
try_join is more sensible, and it might be worth adding it.
I'm more interested on the try_join. Does the following do a try_join?
boost::thread th(fct); th.timed_join(0);
Yes, that would work (though you'd need to specify units: a plain "0" won't compile).
Is this the more efficient way?
I'm not sure what you're asking here. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, November 10, 2008 4:05 PM Subject: Re: [boost] [thread] condition::try_wait() and thread::try_join()?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
From: "Anthony Williams" <anthony.ajw@gmail.com>
try_join is more sensible, and it might be worth adding it.
I'm more interested on the try_join. Does the following do a try_join?
boost::thread th(fct); th.timed_join(0);
Yes, that would work (though you'd need to specify units: a plain "0" won't compile).
Is this the more efficient way?
I'm not sure what you're asking here.
My question is if this is the correct way to know if a thread has finished or if you know a better way? Vicente

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Monday, November 10, 2008 4:05 PM Subject: Re: [boost] [thread] condition::try_wait() and thread::try_join()?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
From: "Anthony Williams" <anthony.ajw@gmail.com>
try_join is more sensible, and it might be worth adding it.
I'm more interested on the try_join. Does the following do a try_join?
boost::thread th(fct); th.timed_join(0);
Yes, that would work (though you'd need to specify units: a plain "0" won't compile).
Is this the more efficient way?
I'm not sure what you're asking here.
My question is if this is the correct way to know if a thread has finished or if you know a better way?
If you want to know if a thread has finished (without waiting for it) then this is currently the only direct way. However, if you want to know if it has finished *the work it was doing* then you might be better off setting a flag in the thread function and checking that. Anthony -- Anthony Williams Author of C++ Concurrency in Action | http://www.manning.com/williams Custom Software Development | http://www.justsoftwaresolutions.co.uk Just Software Solutions Ltd, Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK

----- Original Message ----- From: "Anthony Williams" <anthony.ajw@gmail.com> To: <boost@lists.boost.org> Sent: Tuesday, November 11, 2008 10:45 AM Subject: Re: [boost] [thread] condition::try_wait() and thread::try_join()?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
My question is if this is the correct way to know if a thread has finished or if you know a better way?
If you want to know if a thread has finished (without waiting for it) then this is currently the only direct way. However, if you want to know if it has finished *the work it was doing* then you might be better off setting a flag in the thread function and checking that.
Thanks, Vicente
participants (3)
-
Anthony Williams
-
Oliver Kowalke
-
vicente.botet