Skip to content

Commit 9d48a4e

Browse files
author
Colin Robertson
authored
Merge pull request #3222 from corob-msft/docs/corob/code-only-2480
Merging code files on admin authority. Fix MicrosoftDocs/cpp-docs/issues/2480
2 parents 0305086 + 20ad983 commit 9d48a4e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

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;

0 commit comments

Comments
 (0)