Fix g++ thread compatibility