From 041cc0fa271055a42891d23288f0ce3a40492d8b Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:25:38 +0800 Subject: [PATCH 1/6] Add leading sentence in `` functions reference --- docs/standard-library/thread-functions.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index eea1f7215e..290e9064db 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -8,6 +8,8 @@ helpviewer_keywords: ["std::get_id [C++]", "std::sleep_for [C++]", "std::sleep_u --- # `` functions +The `` header provides the following functions: + ## get_id Uniquely identifies the current thread of execution. From 56f1e26612b58ba39855a93c291f74ef5c4da9cd Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:28:18 +0800 Subject: [PATCH 2/6] Add backticks in `` functions reference --- docs/standard-library/thread-functions.md | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index 290e9064db..4d7f97442a 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -10,7 +10,7 @@ helpviewer_keywords: ["std::get_id [C++]", "std::sleep_for [C++]", "std::sleep_u The `` header provides the following functions: -## get_id +## `get_id` Uniquely identifies the current thread of execution. @@ -20,9 +20,9 @@ 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`](../standard-library/thread-class.md) that uniquely identifies the current thread of execution. -## sleep_for +## `sleep_for` Blocks the calling thread. @@ -34,14 +34,14 @@ inline void 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`](../standard-library/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. @@ -54,14 +54,14 @@ void sleep_until(const xtime *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. @@ -71,17 +71,17 @@ 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. @@ -91,4 +91,4 @@ inline void yield() noexcept; ## See also -[\](../standard-library/thread.md) +[``](../standard-library/thread.md) From ffbcdd6d905c9e057c1b1c5b7c47d639627a18cd Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:29:58 +0800 Subject: [PATCH 3/6] Simplify and improve links in `` functions reference --- docs/standard-library/thread-functions.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index 4d7f97442a..7a69dbea31 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -20,7 +20,7 @@ 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. ## `sleep_for` @@ -35,7 +35,7 @@ inline void sleep_for(const chrono::duration& Rel_time); ### Parameters *`Rel_time`*\ -A [`duration`](../standard-library/duration-class.md) object that specifies a time interval. +A [`duration`](duration-class.md) object that specifies a time interval. ### Remarks @@ -91,4 +91,4 @@ inline void yield() noexcept; ## See also -[``](../standard-library/thread.md) +[``](thread.md) From a7e44972b0f473d50acf6986e31403bee101c32f Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:37:00 +0800 Subject: [PATCH 4/6] Add basic example for `std::this_thread::get_id` in `` functions reference --- docs/standard-library/thread-functions.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index 7a69dbea31..ae8de11685 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -22,6 +22,23 @@ thread::id this_thread::get_id() noexcept; 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; +} +``` + +```Output +Current thread id: 16196 +``` + ## `sleep_for` Blocks the calling thread. From 0b4c1b4927a1b946daf17dcc78abbcaf26715438 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:46:51 +0800 Subject: [PATCH 5/6] Update syntax in `` functions reference --- docs/standard-library/thread-functions.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index ae8de11685..6f5cae74d5 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -44,9 +44,8 @@ Current thread id: 16196 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 @@ -64,9 +63,7 @@ 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 @@ -103,7 +100,7 @@ The function calls `Left.swap(Right)`. 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 From d813e3922814006c9a0cb34c5bbc01a280ea67f5 Mon Sep 17 00:00:00 2001 From: Rageking8 <106309953+Rageking8@users.noreply.github.com> Date: Wed, 30 Jul 2025 18:50:42 +0800 Subject: [PATCH 6/6] Update metadata in `` functions reference --- docs/standard-library/thread-functions.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/standard-library/thread-functions.md b/docs/standard-library/thread-functions.md index 6f5cae74d5..2cba283ccc 100644 --- a/docs/standard-library/thread-functions.md +++ b/docs/standard-library/thread-functions.md @@ -1,9 +1,8 @@ --- -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