C++ Library Extensions
2022.12.09
To help learn modern C++ programming
047-threading_building_blocks.cpp
Go to the documentation of this file.
1
#include <
tpf_output.hpp
>
2
#include <tbb/tbb.h>
3
#include <thread>
4
#include <mutex>
5
6
tpf::sstream
stream
;
7
auto
endl
=
tpf::endl
;
8
9
void
test_threading_building_blocks
()
10
{
11
std::mutex
mutex
;
12
using
lock_type = std::lock_guard<std::mutex>;
13
14
auto
callback = [&
mutex
](
auto
index)
15
{
16
lock_type lock(
mutex
);
17
18
stream
<<
"Thread ID: "
<< std::this_thread::get_id()
19
<<
" - Index: "
<< index <<
endl
;
20
21
};
22
23
tbb::parallel_for
(1, 11, callback);
24
25
}
26
27
int
main
()
28
{
29
stream
<<
"Hello, Intel Threading Building Blocks on Windows!"
30
<<
tpf::endl
;
31
32
test_threading_building_blocks
();
33
}
mutex
std::mutex mutex
Definition:
022-mutex.cpp:12
parallel_for
bool parallel_for(CallbackType &&callback, PolicyType &&policy, BeginType begin_index, EndType end_index)
Definition:
045-parallel_for.cpp:17
stream
tpf::sstream stream
Definition:
047-threading_building_blocks.cpp:6
endl
auto endl
Definition:
047-threading_building_blocks.cpp:7
test_threading_building_blocks
void test_threading_building_blocks()
Definition:
047-threading_building_blocks.cpp:9
main
int main()
Definition:
047-threading_building_blocks.cpp:27
tpf::output::string_stream
Definition:
tpf_output.hpp:844
tpf::endl
constexpr auto endl
Definition:
tpf_output.hpp:973
tpf_output.hpp
Stream output operators << are implemented.
CppExtension
tutorial
047-threading_building_blocks.cpp
Generated by
1.9.4