diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index eea1f7215e..2cba283ccc 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -1,14 +1,15 @@ --- -description: "Learn more about: functions" title: " functions" -ms.date: "11/04/2016" +description: "Learn more about: functions" +ms.date: 11/04/2016 f1_keywords: ["thread/std::get_id", "thread/std::sleep_for", "thread/std::sleep_until", "thread/std::swap", "thread/std::yield"] -ms.assetid: bb1aa1ef-fe3f-4e2c-8b6e-e22dbf2f5a19 helpviewer_keywords: ["std::get_id [C++]", "std::sleep_for [C++]", "std::sleep_until [C++]", "std::swap [C++]", "std::yield [C++]"] --- # `` functions -## get_id +The `` header provides the following functions: + +## `get_id` Uniquely identifies the current thread of execution. @@ -18,48 +19,62 @@ thread::id this_thread::get_id() noexcept; ### Return Value -An object of type [thread::id](../standard-library/thread-class.md) that uniquely identifies the current thread of execution. +An object of type [`thread::id`](thread-class.md#id_class) that uniquely identifies the current thread of execution. + +### Example + +```cpp +#include +#include + +int main() +{ + std::thread::id current_thread_id = std::this_thread::get_id(); + std::cout << "Current thread id: " << current_thread_id; +} +``` -## sleep_for +```Output +Current thread id: 16196 +``` + +## `sleep_for` Blocks the calling thread. ```cpp -template -inline void sleep_for(const chrono::duration& Rel_time); +template +void this_thread::sleep_for(const chrono::duration& Rel_time); ``` ### Parameters -*Rel_time*\ -A [duration](../standard-library/duration-class.md) object that specifies a time interval. +*`Rel_time`*\ +A [`duration`](duration-class.md) object that specifies a time interval. ### Remarks -The function blocks the calling thread for at least the time that's specified by *Rel_time*. This function does not throw any exceptions. +The function blocks the calling thread for at least the time that's specified by *`Rel_time`*. This function does not throw any exceptions. -## sleep_until +## `sleep_until` Blocks the calling thread at least until the specified time. ```cpp template -void sleep_until(const chrono::time_point& Abs_time); - -void sleep_until(const xtime *Abs_time); +void this_thread::sleep_until(const chrono::time_point& Abs_time); ``` ### Parameters -*Abs_time*\ +*`Abs_time`*\ Represents a point in time. ### Remarks This function does not throw any exceptions. -## swap +## `swap` Swaps the states of two `thread` objects. @@ -69,24 +84,24 @@ void swap(thread& Left, thread& Right) noexcept; ### Parameters -*Left*\ +*`Left`*\ The left `thread` object. -*Right*\ +*`Right`*\ The right `thread` object. ### Remarks The function calls `Left.swap(Right)`. -## yield +## `yield` Signals the operating system to run other threads, even if the current thread would ordinarily continue to run. ```cpp -inline void yield() noexcept; +inline void this_thread::yield() noexcept; ``` ## See also -[\](../standard-library/thread.md) +[``](thread.md)