Skip to content

Instantly share code, notes, and snippets.

@dfyz
Created April 14, 2022 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dfyz/8ed3d184a8bb6524d80aa1bd9b83e9b8 to your computer and use it in GitHub Desktop.
Save dfyz/8ed3d184a8bb6524d80aa1bd9b83e9b8 to your computer and use it in GitHub Desktop.
#include <exe/tp/thread_pool.hpp>
#include <exe/fibers/core/api.hpp>
#include <wheels/support/assert.hpp>
#include <chrono>
#include <iostream>
using namespace exe;
int main() {
constexpr size_t kThreadCount = 4;
constexpr size_t kFiberCount = 5000;
tp::ThreadPool scheduler{kThreadCount};
using Clock = std::chrono::system_clock;
using Seconds = std::chrono::duration<double, std::milli>;
const auto start = Clock::now();
std::atomic<uint64_t> counter{0};
for (size_t ii = 0; ii < kThreadCount; ++ii) {
fibers::Go(scheduler, [&] {
for (size_t jj = 0; jj < kFiberCount; ++jj) {
fibers::Go([&] {
++counter;
});
}
});
}
scheduler.WaitIdle();
scheduler.Stop();
const Seconds elapsed = Clock::now() - start;
std::cout << "Running fibers took " << elapsed.count() << " ms" << std::endl;
WHEELS_VERIFY(counter == kThreadCount * kFiberCount, "Bogus counter: " << counter);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment