C++ Multithreading Performance Problem