Thread safety with v5.32/01

Hi,

I thought I’d try out the new thread safe file writing in 5.32

I’ve attached a simple program which creates n TThreads - each TThread has a TFile and a TTree.

If I set n=1, then it runs ok. For n>1 it crashes - there are various ways it crashes. I’ve attached sample outputs below.

Any ideas where I am going wrong?

I am running root 5.32/01 on os x 10.7.3 with gcc version 4.2.1

thanks
Peter

Crash output 1:

root.exe(52952,0x103641000) malloc: *** error for object 0x7f882c16ff60: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

Crash output 2:

===========================================================
There was a crash.
This is the entire stack trace of all threads:

Thread 1 (process 53286):
#0 0x00007fff8e518168 in wait4 ()
#1 0x00007fff85ff55f5 in system ()
#2 0x000000010d991ed9 in TUnixSystem::StackTrace ()
#3 0x000000010d98fc6a in TUnixSystem::DispatchSignals ()
#4
#5 0x000000010d9704cc in TClass::SetUnloaded ()
#6 0x000000010d942924 in ROOT::RemoveClass ()
#7 0x000000010ba4a899 in ROOT::TDefaultInitBehavior::Unregister ()
#8 0x000000010d978704 in ROOT::TGenericClassInfo::~TGenericClassInfo ()
#9 0x00007fff860327c8 in __cxa_finalize ()
#10 0x00007fff86032652 in exit ()
#11 0x000000010b7a661b in start ()

The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.

#5 0x000000010d9704cc in TClass::SetUnloaded ()
#6 0x000000010d942924 in ROOT::RemoveClass ()
#7 0x000000010ba4a899 in ROOT::TDefaultInitBehavior::Unregister ()
#8 0x000000010d978704 in ROOT::TGenericClassInfo::~TGenericClassInfo ()
#9 0x00007fff860327c8 in __cxa_finalize ()
#10 0x00007fff86032652 in exit ()
#11 0x000000010b7a661b in start ()

main.cpp (1.07 KB)

Hi,

The meta data setup is still not (intended) to be thread safe and all TClass and TStreamerInfo needs to be created before doing multi thread access to TFiles. In your example you can add a routine like:void init() { TMemFile file("init.root","RECREATE"); TTree *tr = new TTree("init","initialization tree"); int a; tr->Branch("a", &a, "a/I"); tr->Fill(); file.Write(); file.Close(); }and call it before starting the thread and all will succeed.

Cheers,
Philippe.

Hi Philippe,

oh ok I see - actually I think yourself or perhaps Rene told me that before - but I naively assumed this kind of workaround was now avoidable.

thanks
Peter

Hi,

A priori this limitation will not be lifted until cling becomes the default interpreter.

Cheers
Philippe.

understood - thanks