[DF] Use stacks rather than single output files in Snapshot MT
[DF] Use stacks rather than single output files in Snapshot MT

This resolves ROOT-9456, "[Jenkins][DF] Sporadic failures in test_snapshotNFiles".

The issue is due to interleaved TBB task execution in the same thread.

When nested task spawning is present (i.e. when TBB tasks spawn other
TBB tasks and the thread pool contains at least three threads), the TBB
task stealing mechanism makes it possible that a thread starts executing
a new instance of the "parent" tasks before it finishes the execution of
the previous parent task (this happens when the thread is waiting for a
"stolen" child task to finish, so it steals another threads' parent
task).

In the case of a multi-thread snapshot, one needs to write at least two
branches for the multi-thread branch writing to kick in and have nested
task spawning.

The crash was caused by a new parent task overwriting the output TTree
of the previous parent task in a given thread. When the previous parent
task resumed execution, it ended up trying to flush out the contents of
the deleted output TTree.

The solution adopted is to use thread-local stacks of output TTrees (as
opposed to single output TTrees), that tasks push and pop when they
start and finish respectively.

olifre/root,karies/root,karies/root,root-mirror/root,olifre/root,root-mirror/root,karies/root,root-mirror/root,karies/root,root-mirror/root,olifre/root,olifre/root,root-mirror/root,karies/root,root-mirror/root,karies/root,root-mirror/root,karies/root,root-mirror/root,olifre/root,olifre/root,olifre/root,olifre/root,karies/root,karies/root,karies/root,olifre/root,olifre/root,root-mirror/root,root-mirror/root,root-mirror/root,karies/root,olifre/root