Lines Matching full:thread
9 [section:thread_management Thread Management]
13 #include <boost/thread/thread.hpp>
17 class thread;
18 void swap(thread& lhs,thread& rhs) noexcept;
22 thread::id get_id() noexcept;
59 …for launching and managing threads. Each __thread__ object represents a single thread of execution,
60 or __not_a_thread__, and at most one __thread__ object represents a given thread of execution: obje…
64 allows the details of thread creation to be wrapped in a function.
66 boost::thread make_thread();
70 boost::thread some_thread=make_thread();
79 layer. See <boost/thread/detail/move.hpp> for details.]
83 A new thread is launched by passing an object of a callable type that can be invoked with no parame…
84 object is then copied into internal storage, and invoked on the newly-created thread of execution. …
86 __boost_thread__ must ensure that the referred-to object outlives the newly-created thread of execu…
93 boost::thread copies_are_safe()
96 return boost::thread(x);
97 } // x is destroyed, but the newly-created thread has a copy, so this is OK
99 boost::thread oops()
102 return boost::thread(boost::ref(x));
103 } // x is destroyed, but the newly-created thread still has a reference
111 boost::thread deep_thought_2(find_the_question,42);
113 The arguments are ['copied] into the internal thread structure: if a reference is required, use `bo…
120 [section:attributes Thread attributes]
122 Thread launched in this way are created with implementation defined thread attributes as stack size…
124 the user to set the platform specific attributes. Boost.Thread stay in the middle road through the …
125 thread::attributes which allows to set at least in a portable way the stack size as follows:
127 boost::thread::attributes attrs;
129 boost::thread deep_thought_2(attrs, find_the_question, 42);
135 This is the single attribute that is provided in a portable way. In order to set any other thread a…
138 On PThread platforms the user will need to get the thread attributes handle and use it for whatever…
142 boost::thread::attributes attrs;
154 boost::thread th(attrs, find_the_question, 42);
156 On Windows platforms it is not so simple as there is no type that compiles the thread attributes.
157 There is a linked to the creation of a thread on Windows that is emulated via the thread::attribute…
158 Boost.Thread provides a non portable set_security function so that the user can provide it before t…
160 [/Boost.Thread creates Windows threads that are suspended. Then it calls to the virtual function se…
161 …t inherits from the class thread::attributes that defines a virtual function set_attributes to set…
164 class MyWinTthreadAttributes : boost::thread::attributes
167 void set_attributes(boost::thread::native_handle_type h)
169 // use any specific windows thread setting
179 boost::thread th(attrs, find_the_question, 42);
187 boost::thread::attributes attrs;
194 boost::thread th(attrs, find_the_question, 42);
195 // Set other thread attributes using the native_handle_type.
203 [section:exceptions Exceptions in thread functions]
210 [section:detach Detaching thread]
212 A thread can be detached by explicitly invoking the __detach__ member function on the __thread__
213 object. In this case, the __thread__ object ceases to represent the now-detached thread, and instea…
217 boost::thread t(my_func);
223 [section:join Joining a thread]
225 In order to wait for a thread of execution to finish, the __join__, __join_for or __join_until (__t…
226 used. __join__ will block the calling thread until the thread represented by the __thread__ object …
230 boost::thread t(my_func);
235 If the thread of
241 boost::thread t;
245 …r, except that a call to __join_for or __join_until will also return if the thread being waited for
250 boost::thread t;
260 … __thread__ object that represents a thread of execution is destroyed the thread becomes ['detache…
262 or the program is terminated. A thread can also be detached by explicitly invoking the __detach__ m…
263 object. In this case, the __thread__ object ceases to represent the now-detached thread, and instea…
269 …n the __thread__ object that represents a thread of execution is destroyed the program terminates …
273 boost::thread t(my_func);
276 You can use a thread_joiner to ensure that the thread has been joined at the thread destructor.
281 boost::thread t(my_func);
284 } // here the thread_joiner destructor will join the thread before it is destroyed.
290 A running thread can be ['interrupted] by invoking the __interrupt__ member function of the corresp…
291 interrupted thread next executes one of the specified __interruption_points__ (or if it is currentl…
292 …hen a __thread_interrupted__ exception will be thrown in the interrupted thread. Unless this excep…
293 caught inside the interrupted thread's thread-main function, the stack unwinding process (as with a…
295 thread-main function, this does not cause the call to `std::terminate`; the effect is as though the…
298 If a thread wishes to avoid being interrupted, it can create an instance of __disable_interruption_…
299 interruption for the thread that created them on construction, and restore the interruption state t…
336 At any point, the interruption state for the current thread can be queried by calling __interruptio…
343 current thread, and interruption is requested for the current thread:
345 * [join_link `boost::thread::join()`]
346 * [timed_join_link `boost::thread::timed_join()`]
357 * [link thread.thread_management.thread.sleep `boost::thread::sleep()`]
364 [section:id Thread IDs]
366 Objects of class __thread_id__ can be used to identify threads. Each running thread of execution ha…
368 within the thread. Objects of class __thread_id__ can be copied, and used as keys in associative co…
369 comparison operators is provided. Thread IDs can also be written to an output stream using the stre…
372 Each instance of __thread_id__ either refers to some thread, or __not_a_thread__. Instances that re…
373 compare equal to each other, but not equal to any instances that refer to an actual thread of execu…
374 __thread_id__ yield a total order for every non-equal thread ID.
378 [section:native_in Using native interfaces with Boost.Thread resources]
385 …Thread. An example of bad usage could be detaching a thread directly as it will not change the int…
387 thread t(fct);
388 thread::native_handle_type hnd=t.native_handle();
394 [section:native_from Using Boost.Thread interfaces in a native thread]
397 Any thread of execution created using the native interface is called a native thread in this docume…
399 The first example of a native thread of execution is the main thread.
401 The user can access to some synchronization functions related to the native current thread using th…
411 Of course all the synchronization facilities provided by Boost.Thread are also available on native …
413 …interrupt related functions behave in a degraded mode when called from a thread created using the …
415 As the single way to interrupt a thread is through a __thread__ instance, `interruption_request()` …
421 …ith the current Boost.Thread design, so the use of this function in a POSIX thread result in undef…
427 [section:thread Class `thread`]
429 #include <boost/thread/thread.hpp>
431 class thread
436 thread() noexcept;
437 ~thread();
439 thread(const thread&) = delete;
440 thread& operator=(const thread&) = delete;
443 thread(thread&&) noexcept;
444 thread& operator=(thread&&) noexcept;
447 explicit thread(F f);
449 thread(F &&f);
452 thread(F f,A1 a1,A2 a2,...);
454 explicit thread(F&& f, Args&&... args);
457 explicit thread(attributes& attrs, F f); // EXTENSION
459 thread(attributes& attrs, F &&f); // EXTENSION
461 explicit thread(attributes& attrs, F&& f, Args&&... args);
463 void swap(thread& x) noexcept;
496 bool operator==(const thread& other) const; // DEPRECATED
497 bool operator!=(const thread& other) const; // DEPRECATED
504 void swap(thread& lhs,thread& rhs) noexcept;
508 thread() noexcept;
514 [[Postconditions:] [`this->get_id()==thread::id()`]]
524 thread(thread&& other) noexcept;
528 [[Effects:] [Transfers ownership of the thread managed by `other` (if any) to the newly constructed…
530 [[Postconditions:] [`other.get_id()==thread::id()` and `get_id()` returns the value of `other.get_i…
540 thread& operator=(thread&& other) noexcept;
544 [[Effects:] [Transfers ownership of the thread managed by `other` (if
547 …READ_DONT_PROVIDE_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE: If the thread is joinable call _…
549 - if defined BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE: If the thread is…
552 [[Postconditions:] [`other->get_id()==thread::id()` and `get_id()` returns the value of `other.get_…
561 [section:callable_constructor Thread Constructor]
564 thread(Callable func);
570 [[Effects:] [`func` is copied into storage managed internally by the thread library, and that copy …
571 thread of execution. If this invocation results in an exception being propagated into the internals…
574 …ostconditions:] [`*this` refers to the newly created thread of execution and `this->get_id()!=thre…
580 …y_again] : the system lacked the necessary resources to create an- other thread, or the system-imp…
588 [section:attr_callable_constructor Thread Attributes Constructor EXTENSION]
591 thread(attributes& attrs, Callable func);
597 [[Effects:] [`func` is copied into storage managed internally by the thread library, and that copy …
598 thread of execution with the specified attributes. If this invocation results in an exception being…
600 If the attributes declare the native thread as detached, the boost::thread will be detached.]]
602 …ostconditions:] [`*this` refers to the newly created thread of execution and `this->get_id()!=thre…
608 …y_again] : the system lacked the necessary resources to create an- other thread, or the system-imp…
616 [section:callable_move_constructor Thread Callable Move Constructor]
619 thread(Callable &&func);
625 [[Effects:] [`func` is moved into storage managed internally by the thread library, and that copy i…
626 thread of execution. If this invocation results in an exception being propagated into the internals…
629 …ostconditions:] [`*this` refers to the newly created thread of execution and `this->get_id()!=thre…
635 …y_again] : the system lacked the necessary resources to create an- other thread, or the system-imp…
643 [section:attr_callable_move_constructor Thread Attributes Move Constructor EXTENSION]
646 thread(attributes& attrs, Callable func);
652 [[Effects:] [`func` is copied into storage managed internally by the thread library, and that copy …
653 thread of execution with the specified attributes. If this invocation results in an exception being…
655 If the attributes declare the native thread as detached, the boost::thread will be detached.]]
657 …ostconditions:] [`*this` refers to the newly created thread of execution and `this->get_id()!=thre…
663 …y_again] : the system lacked the necessary resources to create an- other thread, or the system-imp…
672 [section:multiple_argument_constructor Thread Constructor with arguments]
675 thread(F f,A1 a1,A2 a2,...);
682 thread.thread_management.thread.callable_constructor
683 `thread(boost::bind(f,a1,a2,...))`. Consequently, `f` and each `a`n
684 are copied into internal storage for access by the new thread.]]]
686 [[Postconditions:] [`*this` refers to the newly created thread of execution.]]
692 …y_again] : the system lacked the necessary resources to create an- other thread, or the system-imp…
702 [section:destructor Thread Destructor]
704 ~thread();
710 - if defined BOOST_THREAD_DONT_PROVIDE_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE: If the thread…
712 - if defined BOOST_THREAD_PROVIDES_THREAD_DESTRUCTOR_CALLS_TERMINATE_IF_JOINABLE: If the thread is …
716 …thread in its destructor could result in difficult to debug correctness (for `detach`) or performa…
729 [[Returns:] [`true` if `*this` refers to a thread of execution, `false` otherwise.]]
744 [[Preconditions:] [the thread is joinable.]]
746 [[Effects:] [If `*this` refers to a thread of execution, waits for that thread of execution to comp…
748 [[Synchronization:] [The completion of the thread represented by `*this` synchronizes with the
753 …f `*this` refers to a thread of execution on entry, that thread of execution has completed. `*this…
755 [[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_err…
761 [*invalid_argument]: if the thread is not joinable and `BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATI…
765 [*no_such_process]: if the thread is not valid.
792 [[Preconditions:] [the thread is joinable.]]
794 [[Effects:] [If `*this` refers to a thread of execution, waits for that thread of execution to comp…
795 been reach or the specified duration `rel_time` has elapsed. If `*this` doesn't refer to a thread o…
797 [[Returns:] [`true` if `*this` refers to a thread of execution on entry, and that thread of executi…
800 …stconditions:] [If `*this` refers to a thread of execution on entry, and `timed_join` returns `tru…
801 has completed, and `*this` no longer refers to any thread of execution. If this call to `timed_join…
804 [[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_err…
810 [*invalid_argument]: if the thread is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATIS…
814 [*no_such_process]: if the thread is not valid.
832 [[Preconditions:] [the thread is joinable.]]
834 [[Effects:] [If `*this` refers to a thread of execution, waits for that thread of execution to comp…
835 the specified duration `rel_time` has elapsed. If `*this` doesn't refer to a thread of execution, r…
837 [[Returns:] [`true` if `*this` refers to a thread of execution on entry, and that thread of executi…
840 …tconditions:] [If `*this` refers to a thread of execution on entry, and `try_join_for` returns `tr…
841 has completed, and `*this` no longer refers to any thread of execution. If this call to `try_join_f…
844 [[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_err…
850 [*invalid_argument]: if the thread is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATIS…
854 [*no_such_process]: if the thread is not valid.
872 [[Preconditions:] [the thread is joinable.]]
874 [[Effects:] [If `*this` refers to a thread of execution, waits for that thread of execution to comp…
875 been reach. If `*this` doesn't refer to a thread of execution, returns immediately.]]
877 [[Returns:] [`true` if `*this` refers to a thread of execution on entry, and that thread of executi…
880 …conditions:] [If `*this` refers to a thread of execution on entry, and `try_join_until` returns `t…
881 has completed, and `*this` no longer refers to any thread of execution. If this call to `try_join_u…
884 [[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted or `system_err…
890 [*invalid_argument]: if the thread is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATIS…
894 [*no_such_process]: if the thread is not valid.
914 [[Preconditions:] [the thread is joinable.]]
916 [[Effects:] [The thread of execution becomes detached, and no longer has an associated __thread__ o…
918 [[Postconditions:] [`*this` no longer refers to any thread of execution.]]
924 [*no_such_process]: if the thread is not valid.
926 [*invalid_argument]: if the thread is not joinable and BOOST_THREAD_THROW_IF_PRECONDITION_NOT_SATIS…
937 thread::id get_id() const noexcept;
941 [[Returns:] [If `*this` refers to a thread of execution, an instance of __thread_id__ that represen…
956 [[Effects:] [If `*this` refers to a thread of execution, request that the thread will be interrupte…
1015 bool operator==(const thread& other) const;
1035 bool operator!=(const thread& other) const;
1064 [[Effects:] [Suspends the current thread until the specified time has been reached.]]
1066 [[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted.]]
1086 [[Effects:] [See [link thread.thread_management.this_thread.yield `boost::this_thread::yield()`].]]
1094 void swap(thread& other) noexcept;
1098 …reads of execution associated with `*this` and `other`, so `*this` is associated with the thread of
1112 #include <boost/thread/thread.hpp>
1114 void swap(thread& lhs,thread& rhs) noexcept;
1118 [[Effects:] [[link thread.thread_management.thread.swap `lhs.swap(rhs)`].]]
1125 [section:id Class `boost::thread::id`]
1127 #include <boost/thread/thread.hpp>
1129 class thread::id
1166 [[Returns:] [`true` if `*this` and `y` both represent the same thread of execution, or both represe…
1181 …his` and `y` represent different threads of execution, or one represents a thread of execution, and
1201 …ce representing __not_a_thread__ will always compare less than an instance representing a thread of
1271 [section:attributes Class `boost::thread::attributes` EXTENSION]
1273 class thread::attributes {
1295 [[Effects:] [Constructs a thread attributes instance with its default values.]]
1309 [[Effects:] [Stores the stack size to be used to create a thread. This is a hint that the implement…
1325 [[Returns:] [The stack size to be used on the creation of a thread. Note that this function can ret…
1343 thread attributes implementation. If no such instance exists, `native_handle()` and `native_handle_…
1350 [endsect] [/ thread::attributes ]
1351 [endsect] [/ thread ]
1358 thread::id get_id() noexcept;
1384 #include <boost/thread/thread.hpp>
1388 thread::id get_id() noexcept;
1393 [[Returns:] [An instance of __thread_id__ that represents that currently executing thread.]]
1403 #include <boost/thread/thread.hpp>
1412 [[Effects:] [Check to see if the current thread has been interrupted.]]
1422 #include <boost/thread/thread.hpp>
1431 [[Returns:] [`true` if interruption has been requested for the current thread, `false` otherwise.]]
1441 #include <boost/thread/thread.hpp>
1450 [[Returns:] [`true` if interruption has been enabled for the current thread, `false` otherwise.]]
1460 #include <boost/thread/thread.hpp>
1478 [[Effects:] [Suspends the current thread until the time period
1482 [[Throws:] [__thread_interrupted__ if the current thread of execution is interrupted.]]
1492 #include <boost/thread/thread.hpp>
1507 [[Effects:] [Suspends the current thread until the time point specified by
1511 do not throw exceptions. __thread_interrupted__ if the current thread of execution is interrupted. …
1522 #include <boost/thread/thread.hpp>
1537 [[Effects:] [Suspends the current thread until the duration specified
1540 …, Period> do not throw exceptions. __thread_interrupted__ if the current thread of execution is in…
1552 #include <boost/thread/thread.hpp>
1561 [[Effects:] [Gives up the remainder of the current thread's time slice, to allow other threads to r…
1571 #include <boost/thread/thread.hpp>
1585 `boost::this_thread::disable_interruption` disables interruption for the current thread on construc…
1594 …s the current state of __interruption_enabled__ and disables interruption for the current thread.]]
1596 [[Postconditions:] [__interruption_enabled__ returns `false` for the current thread.]]
1610 [[Preconditions:] [Must be called from the same thread from which `*this` was constructed.]]
1612 [[Effects:] [Restores the current state of __interruption_enabled__ for the current thread to that …
1614 [[Postconditions:] [__interruption_enabled__ for the current thread returns the value stored in the…
1626 #include <boost/thread/thread.hpp>
1640 …nce of `boost::this_thread::restore_interruption`, the interruption state for the current thread is
1650 [[Preconditions:] [Must be called from the same thread from which `disabler` was constructed.]]
1652 [[Effects:] [Restores the current state of __interruption_enabled__ for the current thread to that …
1654 [[Postconditions:] [__interruption_enabled__ for the current thread returns the value stored in the…
1668 [[Preconditions:] [Must be called from the same thread from which `*this` was constructed.]]
1670 [[Effects:] [Disables interruption for the current thread.]]
1672 [[Postconditions:] [__interruption_enabled__ for the current thread returns `false`.]]
1684 #include <boost/thread/thread.hpp>
1692 thread-specific storage. This copy is invoked when the current thread
1693 exits (even if the thread has been interrupted).]]
1695 [[Postconditions:] [A copy of `func` has been saved for invocation on thread exit.]]
1698 error occurs within the thread library. Any exception thrown whilst copying `func` into internal st…
1700 [[Note:] [This function is *not* called if the thread was terminated
1701 forcefully using platform-specific APIs, or if the thread is
1715 #include <boost/thread/thread.hpp>
1727 thread* create_thread(F threadfunc);
1728 void add_thread(thread* thrd);
1729 void remove_thread(thread* thrd);
1731 bool is_thread_in(thread* thrd);
1746 [[Effects:] [Create a new thread group with no threads.]]
1767 thread* create_thread(F threadfunc);
1771 [[Effects:] [Create a new __thread__ object as-if by `new thread(threadfunc)` and add it to the gro…
1773 [[Postcondition:] [`this->size()` is increased by one, the new thread is running.]]
1783 void add_thread(thread* thrd);
1799 void remove_thread(thread* thrd);
1821 [[Postcondition:] [Every thread in the group has terminated.]]
1835 [[Returns:] [true if there is a thread `th` in the group such that `th.get_id() == this_thread::get…
1844 bool is_thread_in(thread* thrd);
1848 [[Returns:] [true if there is a thread `th` in the group such that `th.get_id() == thrd->get_id()`.…