Skip to content

Instantly share code, notes, and snippets.

@bakkot
bakkot / threads.cc
Created November 17, 2012 21:00
Example of several surprisingly difficult C++11 threading features
// compile as g++-4.7 --std=c++11 threads.cc -lpthread -o threads
// g++ 4.7.2 will compile fine without the -lpthread, but (at least on my machine) the resulting binary burns and dies. -lpthread does need to occur after the .cc to work, for reasons not clear to me.
#include <iostream>
#include <thread>
#include <mutex>
#include <chrono> // timing, aw yeah
#include <atomic>
#include <cmath> // later irrelevant