I need to spawn worker threads that simply perform a task and exit. All the examples I can find seem to use join() to cleanup the thread resources from another thread. Isn't there some way to declare worker threads so that they "do the right thing" as they exit the thread function? TIA
What is "the right thing"? You don't HAVE to join(). The creating thread will just keep going if you don't. If you join, it waits. If you're passing ownership (e.g. delete responsibility) across thread boundaries, you have to be careful, but that doesn't have much to do with join(). After starting the thread, you can use a condtional in the creator to wait for the thread to "get going" and accept ownership, sort of a "started()" rather than an "ended()", like join(). Or you can flip it around and have the started thread wait on the conditional whilst the creator thread continues to use what will eventually be given to the thread. Is that at all helpful? - Mark dick.bridges@tais.com wrote:
I need to spawn worker threads that simply perform a task and exit. All the examples I can find seem to use join() to cleanup the thread resources from another thread. Isn't there some way to declare worker threads so that they "do the right thing" as they exit the thread function?
TIA
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
BTW: Is there enough of a penalty to creating threads that a thread pool should be used rather than creating them on-demand? I'm curious because I'm using a pool pulling from a work queue. - Mark P.S. I realize "enough" is a bit vague. Mark Sizer wrote:
What is "the right thing"?
You don't HAVE to join(). The creating thread will just keep going if you don't. If you join, it waits.
If you're passing ownership (e.g. delete responsibility) across thread boundaries, you have to be careful, but that doesn't have much to do with join().
After starting the thread, you can use a condtional in the creator to wait for the thread to "get going" and accept ownership, sort of a "started()" rather than an "ended()", like join(). Or you can flip it around and have the started thread wait on the conditional whilst the creator thread continues to use what will eventually be given to the thread.
Is that at all helpful?
- Mark
dick.bridges@tais.com wrote:
I need to spawn worker threads that simply perform a task and exit. All the examples I can find seem to use join() to cleanup the thread resources from another thread. Isn't there some way to declare worker threads so that they "do the right thing" as they exit the thread function?
TIA
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
What is "the right thing"?
You don't HAVE to join(). The creating thread will just keep going if you don't. If you join, it waits.
If you're passing ownership (e.g. delete responsibility) across thread boundaries, you have to be careful, but that doesn't have much to do with join().
After starting the thread, you can use a condtional in the creator to wait for the thread to "get going" and accept ownership, sort of a "started()" rather than an "ended()", like join(). Or you can flip it around and have the started thread wait on the conditional whilst the creator thread continues to use what will eventually be given to the
I'm afraid this thread was started by one of my "senior moments". When
reading ~thread() and join(), I flipped a bit and "saw" join() handled
m_joinable == true and ~thread() handled m_joinable == false. THAT's why I
thought join() had to be called. Your post caused me to go back and read it
again. Now I'm *REALLY* embarrassed.
Thanks for getting me started down the right track.
"Mark Sizer"
Is that at all helpful?
- Mark
dick.bridges@tais.com wrote:
I need to spawn worker threads that simply perform a task and exit. All the examples I can find seem to use join() to cleanup the thread
resources
from another thread. Isn't there some way to declare worker threads so that they "do the right thing" as they exit the thread function?
TIA
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
No problem. I just converted some old threading code to Boost with the help of the list. I'm glad to be able to free Mr. Kempf for more arcane discussions :) - Mark Dick Bridges wrote:
I'm afraid this thread was started by one of my "senior moments". When reading ~thread() and join(), I flipped a bit and "saw" join() handled m_joinable == true and ~thread() handled m_joinable == false. THAT's why I thought join() had to be called. Your post caused me to go back and read it again. Now I'm *REALLY* embarrassed.
Thanks for getting me started down the right track.
"Mark Sizer"
wrote in message news:3EDE8F0A.1090003@15grant.com... What is "the right thing"?
You don't HAVE to join(). The creating thread will just keep going if you don't. If you join, it waits.
If you're passing ownership (e.g. delete responsibility) across thread boundaries, you have to be careful, but that doesn't have much to do with join().
After starting the thread, you can use a condtional in the creator to wait for the thread to "get going" and accept ownership, sort of a "started()" rather than an "ended()", like join(). Or you can flip it around and have the started thread wait on the conditional whilst the creator thread continues to use what will eventually be given to the
thread.
Is that at all helpful?
- Mark
dick.bridges@tais.com wrote:
I need to spawn worker threads that simply perform a task and exit. All the examples I can find seem to use join() to cleanup the thread
resources
from another thread. Isn't there some way to declare worker threads so that they "do the right thing" as they exit the thread function?
TIA
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
Info: http://www.boost.org Wiki: http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl Unsubscribe: mailto:boost-users-unsubscribe@yahoogroups.com
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
participants (3)
-
Dick Bridges
-
dick.bridges@tais.com
-
Mark Sizer