11---
2- description : " Learn more about: <thread> functions"
32title : " <thread> functions"
4- ms.date : " 11/04/2016"
3+ description : " Learn more about: <thread> functions"
4+ ms.date : 11/04/2016
55f1_keywords : ["thread/std::get_id", "thread/std::sleep_for", "thread/std::sleep_until", "thread/std::swap", "thread/std::yield"]
6- ms.assetid : bb1aa1ef-fe3f-4e2c-8b6e-e22dbf2f5a19
76helpviewer_keywords : ["std::get_id [C++]", "std::sleep_for [C++]", "std::sleep_until [C++]", "std::swap [C++]", "std::yield [C++]"]
87---
98# ` <thread> ` functions
109
11- ## <a name =" get_id " ></a > get_id
10+ The ` <thread> ` header provides the following functions:
11+
12+ ## <a name =" get_id " ></a > ` get_id `
1213
1314Uniquely identifies the current thread of execution.
1415
1516``` cpp
16- thread::id this_thread:: get_id () noexcept ;
17+ thread::id get_id () noexcept ;
1718```
1819
1920### Return Value
2021
21- An object of type [ thread::id] ( ../standard-library/thread-class.md ) that uniquely identifies the current thread of execution.
22+ An object of type [ ` thread::id ` ] ( thread-class.md#id_class ) that uniquely identifies the current thread of execution.
23+
24+ ### Example
25+
26+ ``` cpp
27+ #include < iostream>
28+ #include < thread>
29+
30+ int main ()
31+ {
32+ std::thread::id current_thread_id = std::this_thread::get_id();
33+ std::cout << "Current thread id: " << current_thread_id;
34+ }
35+ ```
2236
23- ## <a name =" sleep_for " ></a > sleep_for
37+ ``` Output
38+ Current thread id: 16196
39+ ```
40+
41+ ## <a name =" sleep_for " ></a > ` sleep_for `
2442
2543Blocks the calling thread.
2644
2745``` cpp
28- template <class Rep ,
29- class Period>
30- inline void sleep_for(const chrono::duration<Rep, Period>& Rel_time);
46+ template <class Rep , class Period>
47+ void sleep_for(const chrono::duration<Rep, Period>& Rel_time);
3148```
3249
3350### Parameters
3451
35- *Rel_time*\
36- A [duration](../standard-library/ duration-class.md) object that specifies a time interval.
52+ *` Rel_time` *\
53+ A [` duration`]( duration-class.md) object that specifies a time interval.
3754
3855### Remarks
3956
40- The function blocks the calling thread for at least the time that's specified by *Rel_time*. This function does not throw any exceptions.
57+ The function blocks the calling thread for at least the time that's specified by *` Rel_time` *. This function does not throw any exceptions.
4158
42- ## <a name="sleep_until"></a> sleep_until
59+ ## <a name="sleep_until"></a> ` sleep_until`
4360
4461Blocks the calling thread at least until the specified time.
4562
4663```cpp
4764template <class Clock, class Duration>
4865void sleep_until(const chrono::time_point<Clock, Duration>& Abs_time);
49-
50- void sleep_until(const xtime *Abs_time);
5166```
5267
5368### Parameters
5469
55- * Abs_time* \
70+ * ` Abs_time ` * \
5671Represents a point in time.
5772
5873### Remarks
5974
6075This function does not throw any exceptions.
6176
62- ## <a name =" swap " ></a > swap
77+ ## <a name =" swap " ></a > ` swap `
6378
6479Swaps the states of two ` thread ` objects.
6580
@@ -69,17 +84,17 @@ void swap(thread& Left, thread& Right) noexcept;
6984
7085### Parameters
7186
72- *Left*\
87+ *` Left` *\
7388The left `thread` object.
7489
75- *Right*\
90+ *` Right` *\
7691The right `thread` object.
7792
7893### Remarks
7994
8095The function calls `Left.swap(Right)`.
8196
82- ## <a name="yield"></a> yield
97+ ## <a name="yield"></a> ` yield`
8398
8499Signals the operating system to run other threads, even if the current thread would ordinarily continue to run.
85100
@@ -89,4 +104,4 @@ inline void yield() noexcept;
89104
90105## See also
91106
92- [ \ < thread>] ( ../standard-library/ thread.md)
107+ [ ` <thread> ` ] ( thread.md )
0 commit comments