using fprintf to log in a file is not correct for multithreaded programs