You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/c-language/noreturn.md
+8-5Lines changed: 8 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,21 @@
1
1
---
2
2
title: "_Noreturn keyword and noreturn macro (C11)"
3
3
description: "Describes the `_Noreturn` keyword and `noreturn` macro."
4
-
ms.date: 10/16/2020
4
+
ms.date: 10/19/2020
5
5
f1_keywords: ["_Noreturn_c", "noreturn"]
6
6
helpviewer_keywords: ["keywords [C]"]
7
7
---
8
8
9
9
# `_Noreturn` keyword and `noreturn` macro (C11)
10
10
11
-
The `_Noreturn` keyword was introduced in C11. It tells the compiler that the function it's applied to doesn't return. The compiler knows that the code following a call to a `_Noreturn` function is unreachable.
11
+
The `_Noreturn` keyword was introduced in C11. It tells the compiler that the function it's applied to doesn't return to the caller. The compiler knows that the code following a call to a `_Noreturn` function is unreachable. An example of a function that doesn't return is [abort](../c-runtime-library/reference/abort.md). If there's a possibility for control flow to return to the caller, the function must not have the `_Noreturn` attribute.
12
12
13
-
A convenience macro, `noreturn`, provided in <stdnoreturn.h>, maps to the `_Noreturn` keyword.
13
+
The keyword is typically used through the convenience macro, `noreturn`, provided in <stdnoreturn.h>, which maps to the `_Noreturn` keyword.
14
14
15
15
The primary benefits for using `_Noreturn` (or the equivalent `noreturn`) are making the intention of the function clear in the code for future readers, and detecting unintentionally unreachable code.
16
16
17
+
A function marked `noreturn` shouldn't include a return type because it doesn't return a value to the caller. It should be `void`.
18
+
17
19
## Example using `noreturn` macro and `_Noreturn `keyword
18
20
19
21
The following example demonstrates the `_Noreturn` keyword and the equivalent `noreturn` macro.
@@ -61,5 +63,6 @@ int main(void)
61
63
## See also
62
64
63
65
[/std (Specify language standard version)](../build/reference/std-specify-language-standard-version.md)\
Copy file name to clipboardExpand all lines: docs/parallel/concrt/how-to-create-a-task-that-completes-after-a-delay.md
+8-7Lines changed: 8 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,13 @@
1
1
---
2
-
title: "How to: Create a Task that Completes After a Delay"
3
-
ms.date: "11/04/2016"
2
+
title: "How to: Create a task that completes after a delay"
3
+
description: "Create a task that completes after a delay by using the PPL ConcRT library."
4
+
ms.date: 10/19/2020
4
5
helpviewer_keywords: ["task_completion_event class, example", "create a task that completes after a delay, example [C++]"]
5
6
ms.assetid: 3fc0a194-3fdb-4eba-8b8a-b890981a985d
6
7
---
7
-
# How to: Create a Task that Completes After a Delay
8
+
# How to: Create a task that completes after a delay
8
9
9
-
This example shows how to use the [concurrency::task](../../parallel/concrt/reference/task-class.md), [concurrency::cancellation_token_source](../../parallel/concrt/reference/cancellation-token-source-class.md), [concurrency::cancellation_token](../../parallel/concrt/reference/cancellation-token-class.md), [concurrency::task_completion_event](../../parallel/concrt/reference/task-completion-event-class.md), [concurrency::timer](../../parallel/concrt/reference/timer-class.md), and [concurrency::call](../../parallel/concrt/reference/call-class.md) classes to create a task that completes after a delay. You can use this method to build loops that occasionally poll for data, introduce timeouts, delay handling of user input for a predetermined time, and so on.
10
+
This example shows how to use the [`concurrency::task`](../../parallel/concrt/reference/task-class.md), [`concurrency::cancellation_token_source`](../../parallel/concrt/reference/cancellation-token-source-class.md), [`concurrency::cancellation_token`](../../parallel/concrt/reference/cancellation-token-class.md), [`concurrency::task_completion_event`](../../parallel/concrt/reference/task-completion-event-class.md), [`concurrency::timer`](../../parallel/concrt/reference/timer-class.md), and [`concurrency::call`](../../parallel/concrt/reference/call-class.md) classes to create a task that completes after a delay. You can use this method to build loops that occasionally poll for data. You can also introduce timeouts, delay handling of user input for a predetermined time, and so on.
10
11
11
12
## Example: complete_after and cancel_after_timeout functions
12
13
@@ -15,17 +16,17 @@ The following example shows the `complete_after` and `cancel_after_timeout` func
15
16
> [!TIP]
16
17
> For more information about the `timer` and `call` classes, which are part of the Asynchronous Agents Library, see [Asynchronous Message Blocks](../../parallel/concrt/asynchronous-message-blocks.md).
17
18
18
-
The `cancel_after_timeout` function builds on the `complete_after` function to cancel a task if that task does not complete before a given timeout. The `cancel_after_timeout` function creates two tasks. The first task indicates success and completes after the provided task completes; the second task indicates failure and completes after the specified timeout. The `cancel_after_timeout` function creates a continuation task that runs when the success or failure task completes. If the failure task completes first, the continuation cancels the token source to cancel the overall task.
19
+
The `cancel_after_timeout` function builds on the `complete_after` function to cancel a task if that task doesn't complete before a given timeout. The `cancel_after_timeout` function creates two tasks. The first task indicates success and completes after the provided task completes. The second task indicates failure and completes after the specified timeout. The `cancel_after_timeout` function creates a continuation task that runs when the success or failure task completes. If the failure task completes first, the continuation cancels the token source to cancel the overall task.
The following example computes the count of prime numbers in the range [0, 100000] multiple times. The operation fails if it does not complete in a given time limit. The `count_primes` function demonstrates how to use the `cancel_after_timeout` function. It counts the number of primes in the given range and fails if the task does not complete in the provided time. The `wmain` function calls the `count_primes` function multiple times. Each time, it halves the time limit. The program finishes after the operation does not complete in the current time limit.
25
+
The following example computes the count of prime numbers in the range [0, 100000] multiple times. The operation fails if it doesn't complete in a given time limit. The `count_primes` function demonstrates how to use the `cancel_after_timeout` function. It counts the number of primes in the given range and fails if the task doesn't complete in the provided time. The `wmain` function calls the `count_primes` function multiple times. Each time, it halves the time limit. The program finishes after the operation doesn't complete in the current time limit.
When you use this technique to cancel tasks after a delay, any unstarted tasks will not start after the overall task is canceled. However, it is important for any long-running tasks to respond to cancellation in a timely manner. For more information about task cancellation, see [Cancellation in the PPL](cancellation-in-the-ppl.md).
29
+
When you use this technique to cancel tasks after a delay, any unstarted tasks won't start after the overall task is canceled. However, it's important for any long-running tasks to respond to cancellation quickly. For more information about task cancellation, see [Cancellation in the PPL](cancellation-in-the-ppl.md).
0 commit comments