"Dinkum/threads/thread"get_id
· operator<<
· operator==
· operator!=
· operator<
· operator<=
· operator>
· operator>=
· sleep_for
· sleep_until
· swap
· thread
· yield
Include the header "Dinkum/threads/thread"
to define the class thread and various
supporting functions.
A thread object can be used to observe and manage a thread of execution within an application. A thread object created with the default constructor is not associated with any thread of execution. A thread object constructed with a callable object creates a new thread of execution and calls the callable object in that thread. Thread objects can be moved but not copied; thus, there can be only one thread object associated with any thread of execution.
Every thread of execution has a unique identifier of type
thread::id.
The function this_thread::get_id
returns the identifier of the calling thread; the member function
thread::get_id
returns the identifier of the
thread managed by a thread object. For a default-constructed thread object, the member function thread::get_id returns an object with a value
that is the same for all default-constructed thread objects and different from
the value returned by this_thread::get_id for any thread of
execution that could be joined at the time of the call.
namespace Dinkum {
namespace threads {
class thread;
bool operator==(thread::id Left, thread::id Right);
bool operator!=(thread::id Left, thread::id Right);
bool operator< (thread::id Left, thread::id Right);
bool operator<=(thread::id Left, thread::id Right);
bool operator> (thread::id Left, thread::id Right);
bool operator>=(thread::id Left, thread::id Right);
void swap(thread& Left, thread& Right);
void swap(thread&& Left, thread& Right);
void swap(thread& Left, thread&& Right);
template <class Elem, class Tr>
basic_ostream<Elem, Tr>& operator<<(
basic_ostream<Elem, Tr>& ostr, thread::id id);
namespace this_thread {
thread::id get_id();
void yield();
template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& Rel_time);
template <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration>& Abs_time);
void sleep_until(const xtime *Abs_time);
} // namespace this_thread
} // namespace threads
} // namespace Dinkum
this_thread::get_idthread::id get_id;
The function returns an object of type thread::id that
uniquely identifies the current thread of execution.
operator<<template <class Elem, class Tr>
basic_ostream<Elem, Tr>& operator<<(
basic_ostream<Elem, Tr>& ostr, thread::id id);
The template function overloads operator<< to insert a
text representation of the object id of class
thread::id into the stream ostr. If two objects of
class thread::id compare equal, the inserted text representations
for the two objects will be the same; if they do not compare equal, the
inserted text representations will be different.
operator==bool operator==(thread::id Left, thread::id Right);
The template function overloads operator== to compare two
objects of class thread::id. It returns true if the
two objects represent the same thread of execution or if neither of the two
objects represents a thread of execution, otherwise it returns
false. It does not throw any exceptions.
operator!=bool operator!=(thread::id Left, thread::id Right);
The template function overloads operator!= to compare two
objects of class thread::id. It returns !(Left ==
Right).
operator<bool operator<(thread::id Left, thread::id Right);
The template function overloads operator< to compare two
objects of class thread::id. It defines a total ordering on all
such objects; thus, objects of type thread::id can be used as
keys in associative containers. It does not throw any exceptions.
operator<=bool operator<=(thread::id Left, thread::id Right);
The template function overloads operator<= to compare two
objects of class thread::id. It returns !(Right <
Left).
operator>bool operator>(thread::id Left, thread::id Right);
The template function overloads operator> to compare two
objects of class thread::id. It returns Right <
Left.
operator>=bool operator>=(thread::id Left, thread::id Right);
The template function overloads operator>= to compare two
objects of class thread::id. It returns !(Left <
Right).
this_thread::sleep_fortemplate <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& Rel_time);
The template function blocks the calling thread for at least the time
specified by Rel_time. It does not throw any exceptions.
this_thread::sleep_untiltemplate <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration>& Abs_time);
void sleep_until(const xtime *Abs_time);
The first template function blocks the calling thread at least until the
time specified by Abs_time. It does not throw any exceptions.
In this implementation, the second function blocks the calling thread at
least until the time specified by Abs_time. It does not throw any
exceptions.
swapvoid swap(thread& Left, thread& Right); void swap(thread&& Left, thread& Right); void swap(thread& Left, thread&& Right);
The functions call Left.swap(Right).
threaddetach
· get_id
· hardware_concurrency
· id
· join
· joinable
· native_handle
· native_handle_type
· operator=
· swap
· thread
· ~thread
namespace std {
class thread
{
public:
struct id;
thread();
template <class Fn, class... Args>
explicit thread(Fn&& F, Args&&... A);
thread(thread&& Other);
thread& operator=(thread&& Other);
~thread();
thread(const thread&) = delete;
thread& operator=(const thread&) = delete;
void swap(thread&& Other);
bool joinable() const;
void join();
void detach();
id get_id() const;
static unsigned hardware_concurrency();
typedef h-type native_handle_type;
native_handle_type native_handle();
};
} // namespace std
thread::detachvoid detach();
The member function detaches the thread of execution, if any, associated
with the calling object; thus, the operating system becomes responsible for
releasing any resources owned by the thread when the thread terminates. After
a call to detach(), a call to get_id() returns
id().
If the thread associated with the calling object is not
joinable,
the function throws an object of type
system_error with an error code of
invalid_argument. If the thread associated with the calling
object is invalid, the function throws an object of type
system_error with an error code of
no_such_process.
thread::get_idid get_id() const;
The member function returns an object of type thread::id that
uniquely identifies the thread of execution associated with this object, or
thread::id() if there is no thread of execution associated with
this object.
thread::hardware_concurrencyunsigned hardware_concurrency();
The static member function returns an estimate of the number of hardware thread contexts. If this value cannot be computed or is not well defined it returns 0.
thread::idstruct id {
id();
};
The struct thread::id provides a unique identifier for each
thread of execution in the process. Its default constructor creates an object
that does not compare equal to the thread::id object for any
existing thread. All default-constructed thread::id objects
compare equal.
thread::joinvoid join();
The member function blocks until the thread of execution associated with
the calling object completes. If the call succeeds, subsequent calls to
get_id() for the calling object return id(); if the
call does not succeed, the value returned by get_id() is
unchanged.
If the thread associated with the calling object is not
joinable,
the function throws an object of type
system_error with an error code of
invalid_argument. If the thread associated with the calling
object is the current thread (i.e. get_id() ==
this_thread::get_id()) or if the system otherwise detects that a
deadlock would occur, the function throws an object of type
system_error with an error code of
resource_deadlock_would_occur. If the thread associated with the
calling object is invalid, the function throws an object of type
system_error with an error code of
no_such_process.
thread::joinablebool joinable() const;
The member function returns true if the thread of execution
associated with the calling object is
joinable,
otherwise false.
A thread object is joinable if get_id()
!= id().
thread::native_handlenative_handle_type native_handle();
The member function returns an object of type
native_handle_type that can be used in implementation-specific
ways.
thread::native_handle_typetypedef h-type native_handle_type;
The typedef is a synonym for an implementation-specific type that can be used in implementation-specific ways.
In this implementation,
it is a synonym for thrd_t, and can be used as an argument to any
of the thrd_XXX functions other than
thrd_create.
thread::operator=thread& operator=(thread&& Right);
The member function calls detach() if the calling object is
joinable. Regardless, it then associates the
calling object with the thread associated with Right and sets
Right to a default-constructed state.
thread::swapvoid swap(thread&& Other);
The member function swaps the states of the calling object and
Other.
thread::threadthread();
template <class Fn, class... Args>
explicit thread(Fn&& F, Args&&... A);
thread(thread&& Other);
The first constructor constructs an object that is not associated with any
thread of execution. The value returned by a call to get_id() for
such an object compares equal to thread::id().
The second constructor constructs an object that is associated
with a new thread of execution and executes
INVOKE(F, t1, t2, ..., tN)
(where t1, t2, ..., tN are the values in args...)
in the new thread. Each constructor calls terminate()
if the call to F terminates with an uncaught exception.
The third constructor constructs an object that is associated with the
the thread associated with Other and sets
Other to a default-constructed state.
thread::~thread~thread();
The destructor calls detach() if the thread object is
joinable.
this_thread::yieldvoid yield();
The function tells the operating system that it may run other threads even if the current thread would ordinarily continue to run.
See also the Table of Contents and the Index.
Copyright (c) by P.J. Plauger. All rights reserved.