replace pthreads with std::mutex