thread safety of reading and writing file