The problem is fixed by calling
ROOT::EnableThreadSafety();
from the #include <TROOT.h> header.
#include <TROOT.h>