Added thread safety in IOHandler.write