C++ flavored solution using the built in threads and mutexes Simply clone and run: g++ -std=c++11 C++/src/main.cpp && ./a.out.