Message: Re: G4Cache vs static G4ThreadLocal when there is only one class instance Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Feedback Re: G4Cache vs static G4ThreadLocal when there is only one class instance 

Forum: Multithreading
Re: None G4Cache vs static G4ThreadLocal when there is only one class instance
Date: 15 Aug, 2016
From: Andrea Dotti <Andrea Dotti>

Hello Anders, in the specific case of detector construction, since only one instance of it exists at any given time, cases F and H from the twiki are the same. So one could use either of static G4ThreadLocal or G4Cache<>. The latter has a very small performance penalty (only relevant for cases in which one access the underlying object in the event loop).

The difference between the two is that the G4Cache<> should be used when one wants to give, to a thread-shared object, a data field that has the behavior of thread- and instance-private (case H).

The examples just show how to use the two, but in this particular case they are equivalent.

To summarize: while for this specific case G4ThreadLocal and G4Cache<> are equivalent, they are not in the general case and they serve very different purposes.

Hope this helps, Andrea

 Add Message Add Message
to: "Re: G4Cache vs static G4ThreadLocal when there is only one class instance"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews