Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make libsthtread valgrind-aware.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 1 Jul 2022 15:04:19 +0000 (17:04 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sat, 2 Jul 2022 19:59:31 +0000 (21:59 +0200)
commit5e456059d43336fe91a373969f4a2c983ae844f9
treeed317fab279c00880a31c8e539e3698e570e0e3d
parentb89a1ce004bff692ee331f4f76047b414d07b696
Make libsthtread valgrind-aware.

Without this change, libsthread is initialized twice when using valgrind:
one for the valgrind launcher, and one for the target program.

Use the environment variable VALGRIND_LIB to detect the usage of valgrind,
and don't divert main() when RUNNING_ON_VALGRIND returns 0.

Just hope that noboby has VALGRIND_LIB in its environment without using valgrind.
In this case, the check can be reinforced by looking for the substring "valgrind" in argv[0].

For example, run:
valgrind --trace-children=yes env LD_PRELOAD=./lib/libsthread.so ./examples/sthread/pthread-mutex-simple
src/sthread/sthread.c