Fix multithreading issues in ROOT I/O