-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSimpleThreading_03.cpp
More file actions
50 lines (33 loc) · 1.17 KB
/
SimpleThreading_03.cpp
File metadata and controls
50 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// ===========================================================================
// Moving a Thread object // SimpleThreading_03.cpp
// ===========================================================================
#include <iostream>
#include <thread>
#include <chrono>
#include "../Logger/Logger.h"
namespace SimpleThreading03 {
constexpr size_t NumIterations{ 5 };
static void function(int value) {
for (size_t i{}; i != NumIterations; ++i) {
Logger::log(std::cout, "in thread ", value);
std::this_thread::sleep_for(std::chrono::seconds{ 1 });
}
Logger::log(std::cout, "Done Thread.");
}
static void test() {
Logger::log(std::cout, "Begin");
std::thread t1{ function, 1 };
std::this_thread::sleep_for(std::chrono::seconds{ 1 });
std::thread t2{ std::move(t1) };
t2.join();
Logger::log(std::cout, "Done.");
}
}
void test_simple_threading_03()
{
using namespace SimpleThreading03;
test();
}
// ===========================================================================
// End-of-File
// ===========================================================================