Hi,
I have a segmentation fault when I concurrently delete TMemFiles which have a TTree (even empty) inside. If I surround the delete instruction with TThread::Lock-UnLock, I don’t have any issue.
Minimal code to reproduce the segfault:
void *thread(void * ptri){
Long_t tid = (Long_t) ptri;
Info("Thread", "tid: %d", tid);
char fname[10];
sprintf(fname, "f%d.root", tid);
TMemFile *memFile = new TMemFile(fname, "new");
char tname[10];
sprintf(tname, "tree_%d", tid);
TTree *tree = new TTree(tname, tname);
//TThread::Lock();
delete memFile;
//TThread::UnLock();
}
void threadsafe_issue(){
Int_t nbThread = 20;
TThread::Initialize();
TThread **threads = new TThread*[nbThread];
for(Long_t i=0 ; i<nbThread ; i++){
char tname[5];
sprintf(tname, "h_%d", i);
threads[i] = new TThread(tname, thread, (void *) i);
threads[i]->Run();
}
for(Long_t i=0 ; i<nbThread ; i++){
threads[i]->Join();
delete threads[i];
}
delete[] threads;
}
and the ROOT ouput, segfault.txt (12.2 KB).
Thank you.