|
Boost Users : |
Subject: Re: [Boost-users] Questions about packaged_task , Promise and serialization of a class object and event handling
From: Igor R (boost.lists_at_[hidden])
Date: 2012-04-16 02:19:53
> ok talking about threads ,how can i query a thread object to see if it
> points to a valid thread of execution ? will just comparing it with null! do
> it ? i mean specially after using join() or detach() on them ( i dont know
> if that was necessary!)
use joinable() member function:
http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#thread.thread_management.thread.joinable
> question two : when i detach a thread, do i really loose it for good ? cant
> i have any access of any kind to it ? any kind of management ? checking it ?
After you detach() the object from its thread, the object is no longer
associated with the thread:
http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#thread.thread_management.thread.detach
Of course, the thread continues to run.
> suppose my detached thread was to run a function named "somefunc()", will i
> access the thread in there ?
If you mean using namespace this_thread, you can use its facilities
even if there's no a thread object associated with this thread.
You can also compare this_thread::get_id() to a stored thread::id
object of another thread even if it's already detached from its
object.
> i mean can i have any kind of management in that thread ? by management i mean get its id for example in case to
> differentiate it from other possible detached! or joined?
No, you can't do virtually anything with a detached thread object.
Detaching it means that you do not want to manage the underlying
thread of execution by means of thread object.
> do i have to immediately write thread.join() in order for my thread to join
> with the main thread ?
Calling join() on detached thread object won't have any effect:
http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#thread.thread_management.thread.join
> do we have any means in pausing /resuming a thread ?
You've got interruption point:
http://www.boost.org/doc/libs/1_49_0/doc/html/thread/thread_management.html#interruption_points
> rather than using the e.g windows api ?
Pausing/resuming threads with winapi is usually a bad idea (other than
for debugging purposes), as you never know *where* it's paused. What
can you do with such a thread?
> how would i want to use pointers in a multi threaded application ? i mean do
> i even need one of those smart pointers ? if i do, would you name some of
> scenarios that might need the use of smart pointers? i would be grateful
It depends on the design of your program.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net