YACLib
C++ library for concurrent tasks execution
Loading...
Searching...
No Matches
thread_pool.cpp
Go to the documentation of this file.
1/**
2 * \example fair_thread_pool.cpp
3 * Simple \ref IThreadPool examples
4 */
5
9
10#include <cstddef>
11#include <iostream>
12
13#include <gtest/gtest.h>
14
15namespace test {
16namespace {
17
18TEST(Example, FairThreadPool) {
19 std::cout << "FairThreadPool" << std::endl;
20
22
23 std::atomic<std::size_t> counter{0};
24
25#if YACLIB_FAULT == 1
26 constexpr std::size_t kIncrements = 1000;
27#else
28 constexpr std::size_t kIncrements = 100500;
29#endif
30
31 for (std::size_t i = 0; i < kIncrements; ++i) {
32 Submit(tp, [&counter] {
33 counter.store(counter.load() + 1);
34 });
35 }
36
37 tp.Stop();
38 tp.Wait();
39
40 std::cout << "Counter value = " << counter << ", expected " << kIncrements << std::endl;
41
42 std::cout << std::endl;
43}
44
45} // namespace
46} // namespace test
TODO(kononovk) Doxygen docs.
void Submit(IExecutor &executor, Func &&f)
Submit given func for details.
Definition submit.hpp:17
TEST(Example, HelloWorld)
Definition simple.cpp:27