- Treiber Stack
- MSQueue
- Flat combining stack
Project contains some popular synchronization primitives implementation:
You can use doxygen to get docs.
doxygen Doxyfile
Usage examples:
synchronize::tp::ThreadPool scheduler{2};
fiber::IoService io(9000);
scheduler.Start();
fiber::Go(scheduler, [&] {
while (true) {
auto socket_ptr = io.Accept(); // fiber will be suspended, while asynchronous accept works
fiber::Go(scheduler, [&wg, &io, socket_ptr]() mutable {
while (true) {
auto res = io.ReadSome(*socket_ptr); // fiber will be suspended, while asynchronous read works
io.Write(*socket_ptr, res); // fiber will be suspended, while asynchronous write works
}
});
}
});
io.RunService();
scheduler.Stop();
synchronize::tp::ThreadPool scheduler{2};
scheduler.Start();
synchronize::WaitGroup wg;
std::atomic<int> x{0};
for (size_t i = 0; i < 400000; ++i) {
wg.Add(1);
fiber::Go(scheduler, [&wg, &scheduler, &x] {
utils::Defer def([&wg]() { wg.Done(); });
for (size_t j = 0; j < 100; ++j) {
++x;
fiber::Yield();
}
});
}
wg.Wait();
std::cout << x.load();
scheduler.Stop();
synchronize::tp::ThreadPool tp(4);
std::atomic<int> cnt = 0;
tp.Start();
synchronize::WaitGroup wg;
for (size_t i = 0; i < 1000; ++i) {
wg.Add(1);
tp.Submit(
[&, k=i]() {
utils::Defer def([&wg]() { wg.Done(); });
for (size_t i = 0; i < 10000; ++i) {
++cnt;
}
}
);
}
wg.Wait();
std::cout << cnt << std::endl;
tp.Stop();
std::cout << cnt << std::endl;
- GoogleTest (used for Testing)