-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreads.cpp
More file actions
39 lines (29 loc) · 1 KB
/
threads.cpp
File metadata and controls
39 lines (29 loc) · 1 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
/*
Multithreading is a specialized form of multitasking and a multitasking is the feature that allows your computer to run two or more programs concurrently.
In general, there are two types of multitasking: process-based and thread-based.
Process-based multitasking handles the concurrent execution of programs.
Thread-based multitasking deals with the concurrent execution of pieces of the same program.
A multithreaded program contains two or more parts that can run concurrently.
Each part of such a program is called a thread, and each thread defines a separate path of execution.
*/
#include <iostream>
#include <thread>
static bool s_finished = false;
void DoWork()
{
using namespace std::literals::chrono_literals;
while (!s_finished)
{
std::cout << "Working...\n";
std::this_thread::sleep_for(1s);
}
}
int main()
{
std::thread worker(DoWork);
std::cin.get();
s_finished = true;
worker.join();
std::cout << "Finished...\n";
std::cin.get();
}