Tracing/Profiling D Applications
Ali Çehreli
acehreli at yahoo.com
Wed May 25 21:56:41 UTC 2022
On 5/25/22 14:35, Christian Köstlin wrote:
> 1. I went for a singleton for storing tracing/logging information that
> needs to be initialized manually. Is __gshared the right way to do that?
I think this is where thread-local storage comes in handy. As the D
runtime does for dmd's -profile command line switch, you can have a
module-level Appender, which collects data for that thread without
worrying about race conditions.
> to unlock the mutex?
You need the mutex only when each thread is exiting to combine their
results. Each static ~this() could grab the mutex and add its result to
the one global Appender. And that "global" Appender would be 'shared' or
__gshared; doesn't matter.
Ali
More information about the Digitalmars-d-learn
mailing list