xrpld
Loading...
Searching...
No Matches
nix
docker
test_files
cpp_sources
regular.cpp
1
#include <
iostream
>
2
#include <
mutex
>
3
#include <
thread
>
4
#include <
vector
>
5
6
static
std::mutex
gMutex;
7
8
void
9
worker(
int
id
)
10
{
11
std::lock_guard<std::mutex>
lock
(gMutex);
12
std::cout
<<
"Hello from thread "
<<
id
<<
"\n"
;
13
}
14
15
int
16
main()
17
{
18
constexpr
int
kNumThreads = 10;
19
std::vector<std::thread>
threads;
20
threads.
reserve
(kNumThreads);
21
for
(
int
i = 0; i < kNumThreads; ++i)
22
threads.
emplace_back
(worker, i);
23
for
(
auto
& t : threads)
24
t.join();
25
26
std::cout
<<
"Hello from main thread\n"
;
27
return
0;
28
}
std::cout
std::vector::emplace_back
T emplace_back(T... args)
iostream
std::lock_guard
std::lock
T lock(T... args)
mutex
std::vector::reserve
T reserve(T... args)
thread
vector
Generated by
1.16.1