Re: [ROOT] TTree with TThread ?
From: Joern Adamczewski (J.Adamczewski@gsi.de)
Date: Thu Apr 27 2000 - 16:20:33 MEST
attached mail follows:
Hello Yun-Ha Shin,
when testing the root TThread classes, we also
tried the filling and readout of a TTree from different
threads.
Consider the TTree as a global object,
then both threads can access the tree.
(this also works if the tree is member of a class and
the threads are calling memberfunctions of the same class, which
are acting on the tree object).
Anyway, you _must_ protect all TTree actions calling
TThread::Lock() and TThread::Unlock() in both threads
(this uses the TThread class internal main mutex) e.g.:
TThread::Lock();
// here is any thread action on tree, e.g.:
fTree->Fill();
TThread::UnLock();
This will block the other thread to use the tree while it is modified by
thread one.
(see also the TThread howto on
http://www-linux.gsi.de/~go4/HOWTOthreads/)
However, I encountered problems with the TTree autosave feature; if
thread 1 fills the tree, it is automatically written to a TFile
(which should be open before the TTree is created)after a predefined
amount of data. If thread 2 simultaneously tries to loop on the tree
beginning from the first
entry, it seems to read the events from the file (?), which slows it
down. The program might also
crash after the second autosave cycle (?). Moreover, it is a bad idea to
write the tree to a file
by a third thread, while thread 1 fills it and thread 2 reads it out...
I did not investigate the reason for this conflicts further, since we did
not urgently need the
threaded access to TTrees; we made this tests last year using root
2.21-09 with a pre-version of
the TThread classes. Probably there is a different behaviour now.
Hope this might help a bit. It would be great if you
could tell me your experiences with TThread and TTrees.
Best regards,
Joern
Yun-Ha Shin wrote:
> Hi,
>
> Is it possible to use TTree/TNtuple with multiple threads ?
>
> For example, one thread is writing/filling data to TTree continuously.
> Sometimes later it is required to look at some part of the data in the
> Tree.
> Is it possible to run safely another thread to get those data from the
> Tree
> without corrupting Tree; like a producer-consumer ?
>
> Thanks,
> Yun-Ha.
--
/////////////////////////////////////////////////////////////////
// Dr. J"orn Adamczewski (J.Adamczewski@gsi.de) //
// GO4 project team, Datenverarbeitung & Experiment-Elektronik //
// Gesellschaft f"ur Schwerionenforschung Darmstadt, Germany //
/////////////////////////////////////////////////////////////////
This archive was generated by hypermail 2b29
: Tue Jan 02 2001 - 11:50:24 MET