Skip to content

Instantly share code, notes, and snippets.

@MBkkt
Last active April 17, 2022 18:57
Show Gist options
  • Save MBkkt/2cd5058eb86b5d8d45781245cf6cb748 to your computer and use it in GitHub Desktop.
Save MBkkt/2cd5058eb86b5d8d45781245cf6cb748 to your computer and use it in GitHub Desktop.
#include <exe/tp/thread_pool.hpp>
#include <exe/fibers/core/api.hpp>
#include <exe/fibers/sync/mutex.hpp>
#include <exe/fibers/sync/wait_group.hpp>
#include <wheels/support/stop_watch.hpp>
#include <iostream>
#include <chrono>
using namespace exe;
using namespace std::chrono_literals;
int main() {
tp::ThreadPool scheduler{/*threads=*/4};
fibers::Mutex m;
auto task = [&] {
m.Lock();
std::this_thread::sleep_for(100ms);
m.Unlock();
std::this_thread::sleep_for(100ms);
};
wheels::StopWatch stop_watch;
fibers::Go(scheduler, task);
fibers::Go(scheduler, task);
fibers::Go(scheduler, task);
fibers::Go(scheduler, task);
scheduler.WaitIdle();
std::cout << stop_watch.Elapsed().count() / 1e9 << std::endl; // 0.8
scheduler.Stop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment