Thread-safety of a profiled binary (and GCOV runtime library)

Nathan Sidwell nathan@acm.org
Mon Jul 25 12:23:00 GMT 2016


On 07/25/16 08:14, Richard Biener wrote:

> There's pthread_detach () - do we wrap that appropriately?  That said, another
> way to make counters thread-safe is to allocate per-thread counters and update
> those (for example by making the counters __TLS).  The interesting part is then
> to merge them with the main set of counters during thread exit (properly locked
> or atomically of course).  This would also solve the above mentioned issue but
> have quite a cost on the memory side.

I'm not aware of any of the pthread fns being wrapped.  (IIRC it's fork, execFOO 
and exit).

As you say, having TLS counters would increase memory, but I have no feel for 
the relative increase it might be in codebases it'd affect.   Compute-wise it's 
probably no more expensive than using atomic adds, probably cheaper, if the 
atomic ops are fn calls.

nathan



More information about the Gcc mailing list