Skip to content

Commit 1901663

Browse files
authored
Merge pull request #3223 from MicrosoftDocs/master
10/20/2020 AM Publish
2 parents f19f02f + 651f3e0 commit 1901663

File tree

5 files changed

+24
-19
lines changed

5 files changed

+24
-19
lines changed

docs/c-language/noreturn.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
---
22
title: "_Noreturn keyword and noreturn macro (C11)"
33
description: "Describes the `_Noreturn` keyword and `noreturn` macro."
4-
ms.date: 10/16/2020
4+
ms.date: 10/19/2020
55
f1_keywords: ["_Noreturn_c", "noreturn"]
66
helpviewer_keywords: ["keywords [C]"]
77
---
88

99
# `_Noreturn` keyword and `noreturn` macro (C11)
1010

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.
1212

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.
1414

1515
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.
1616

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+
1719
## Example using `noreturn` macro and `_Noreturn `keyword
1820

1921
The following example demonstrates the `_Noreturn` keyword and the equivalent `noreturn` macro.
@@ -61,5 +63,6 @@ int main(void)
6163
## See also
6264
6365
[/std (Specify language standard version)](../build/reference/std-specify-language-standard-version.md)\
64-
[/W4 (Specify warning level)](../build/reference/compiler-option-warning-level.md)
65-
[C4702 warning](../error-messages\compiler-warnings\compiler-warning-level-4-c4702.md)
66+
[/W4 (Specify warning level)](../build/reference/compiler-option-warning-level.md)\
67+
[C4702 warning](../error-messages\compiler-warnings\compiler-warning-level-4-c4702.md)\
68+
[__declspec(noreturn)](../cpp/noreturn.md)

docs/mfc/reference/coblist-class.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.assetid: 80699c93-33d8-4f8b-b8cf-7b58aeab64ca
77
---
88
# CObList Class
99

10-
fSupports ordered lists of nonunique `CObject` pointers accessible sequentially or by pointer value.
10+
Supports ordered lists of nonunique `CObject` pointers accessible sequentially or by pointer value.
1111

1212
## Syntax
1313

docs/parallel/concrt/codesnippet/CPP/how-to-create-a-task-that-completes-after-a-delay_2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ bool count_primes(unsigned int max_value, unsigned int timeout)
1919

2020
// Create a task that computes the count of prime numbers.
2121
// The task is canceled after the specified timeout.
22-
auto t = cancel_after_timeout(task<size_t>([max_value, timeout]
22+
auto t = cancel_after_timeout(task<size_t>([max_value, timeout, cts]
2323
{
2424
combinable<size_t> counts;
25-
parallel_for<unsigned int>(0, max_value + 1, [&counts](unsigned int n)
25+
parallel_for<unsigned int>(0, max_value + 1, [&counts, cts](unsigned int n)
2626
{
2727
// Respond if the overall task is cancelled by canceling
2828
// the current task.
@@ -52,7 +52,7 @@ bool count_primes(unsigned int max_value, unsigned int timeout)
5252
<< timeout << L" ms." << endl;
5353
return true;
5454
}
55-
catch (const task_canceled& e)
55+
catch (const task_canceled&)
5656
{
5757
wcout << L"The task timed out." << endl;
5858
return false;

docs/parallel/concrt/codesnippet/CPP/how-to-create-a-task-that-completes-after-a-delay_3.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// task-delay.cpp
22
// compile with: /EHsc
3+
#include <ppl.h>
34
#include <ppltasks.h>
45
#include <agents.h>
56
#include <iostream>
@@ -91,10 +92,10 @@ bool count_primes(unsigned int max_value, unsigned int timeout)
9192

9293
// Create a task that computes the count of prime numbers.
9394
// The task is canceled after the specified timeout.
94-
auto t = cancel_after_timeout(task<size_t>([max_value, timeout]
95+
auto t = cancel_after_timeout(task<size_t>([max_value, timeout, cts]
9596
{
9697
combinable<size_t> counts;
97-
parallel_for<unsigned int>(0, max_value + 1, [&counts](unsigned int n)
98+
parallel_for<unsigned int>(0, max_value + 1, [&counts, cts](unsigned int n)
9899
{
99100
// Respond if the overall task is cancelled by canceling
100101
// the current task.
@@ -124,7 +125,7 @@ bool count_primes(unsigned int max_value, unsigned int timeout)
124125
<< timeout << L" ms." << endl;
125126
return true;
126127
}
127-
catch (const task_canceled& e)
128+
catch (const task_canceled&)
128129
{
129130
wcout << L"The task timed out." << endl;
130131
return false;

docs/parallel/concrt/how-to-create-a-task-that-completes-after-a-delay.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
---
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
45
helpviewer_keywords: ["task_completion_event class, example", "create a task that completes after a delay, example [C++]"]
56
ms.assetid: 3fc0a194-3fdb-4eba-8b8a-b890981a985d
67
---
7-
# How to: Create a Task that Completes After a Delay
8+
# How to: Create a task that completes after a delay
89

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.
1011

1112
## Example: complete_after and cancel_after_timeout functions
1213

@@ -15,17 +16,17 @@ The following example shows the `complete_after` and `cancel_after_timeout` func
1516
> [!TIP]
1617
> 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).
1718
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.
1920

2021
[!code-cpp[concrt-task-delay#1](../../parallel/concrt/codesnippet/cpp/how-to-create-a-task-that-completes-after-a-delay_1.cpp)]
2122

2223
## Example: Compute count of prime numbers
2324

24-
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.
2526

2627
[!code-cpp[concrt-task-delay#2](../../parallel/concrt/codesnippet/cpp/how-to-create-a-task-that-completes-after-a-delay_2.cpp)]
2728

28-
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).
2930

3031
## Complete code example
3132

0 commit comments

Comments
 (0)