Skip to content

Instantly share code, notes, and snippets.

Created February 12, 2014 11:51
Show Gist options
  • Save anonymous/9861f0dbf6bd89b02ee3 to your computer and use it in GitHub Desktop.
Save anonymous/9861f0dbf6bd89b02ee3 to your computer and use it in GitHub Desktop.
#include <nonius/main.h++>
#include <mutex>
#include <thread>
#include <condition_variable>
std::mutex m0;
std::condition_variable c0;
std::unique_lock<std::mutex> l0(m0);
NONIUS_BENCHMARK("no one waiting", []{ c0.notify_all(); })
std::mutex m1;
std::condition_variable c1;
std::unique_lock<std::mutex> l1(m1);
std::thread waiter([]{ while(true) { c1.wait(l1); } }); // Not entirely guaranteed to be always waiting :(
NONIUS_BENCHMARK("someone waiting", []{ c1.notify_all(); })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment