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
8
10{
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
27int main()
28{
29 stream <<"Hello, Intel Threading Building Blocks on Windows!"
30 << tpf::endl;
31
33}
std::mutex mutex
Definition: 022-mutex.cpp:12
bool parallel_for(CallbackType &&callback, PolicyType &&policy, BeginType begin_index, EndType end_index)
tpf::sstream stream
void test_threading_building_blocks()
constexpr auto endl
Definition: tpf_output.hpp:973
Stream output operators << are implemented.