SUMMARY Helgrind reports an error in the very simple code below: STEPS TO REPRODUCE In any .c file: #include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <unistd.h> void *routine(void *nop) { usleep(1); return (nop); } int main(void) { int i; int max; pthread_t *threads; i = 0; max = 5; threads = malloc(sizeof(*threads) * max); while (i < max) if (pthread_create((threads + i++), NULL, &routine, NULL)) exit (1); i = 0; while (i < max) if (pthread_join(*(threads + i++), NULL)) exit (2); free(threads); return (0); } OBSERVED RESULT ==3537== Helgrind, a thread error detector ==3537== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==3537== Using Valgrind-3.19.0 and LibVEX; rerun with -h for copyright info ==3537== Command: ./a.out ==3537== Helgrind: hg_main.c:5379 (hg_handle_client_request): Assertion 'found' failed. host stacktrace: ==3537== at 0x58026BCA: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) ==3537== by 0x58026CF7: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) ==3537== by 0x58026E9B: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) ==3537== by 0x5801014A: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) ==3537== by 0x5803B454: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) ==3537== by 0x58082CC7: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) ==3537== by 0x580C97C0: ??? (in /usr/lib/valgrind/helgrind-amd64-linux) sched status: running_tid=1 Thread 1: status = VgTs_Runnable (lwpid 3537) ==3537== at 0x484A943: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==3537== by 0x10924D: main (in /home/adrien/Prog/philosophers/a.out) client stack range: [0x1FFEFFE000 0x1FFF000FFF] client SP: 0x1FFF000390 valgrind stack range: [0x1002E8E000 0x1002F8DFFF] top usage: 8880 of 1048576 Note: see also the FAQ in the source distribution. It contains workarounds to several common problems. In particular, if Valgrind aborted or crashed after identifying problems in your program, there's a good chance that fixing those problems will prevent Valgrind aborting or crashing, especially if it happened in m_mallocfree.c. If that doesn't help, please report this bug to: www.valgrind.org In the bug report, send all the above text, the valgrind version, and what OS and version you are using. Thanks. EXPECTED RESULT No errors SOFTWARE/OS VERSIONS Tested on several systems (Ubuntu20.04 and arch) ADDITIONAL INFORMATION
Works for me on debian 11.4 Can you re-run your test program with debug info under a valgrind itself compiled with debug info and using more trace (such as -d -d -d --trace-sched=yes) and attach the resulting log file ? Thanks Philippe
Also works for me on RHEL 7.6, Valgrind 3.13 3.15 and git head.
I’ve had the same issue but found it was due using my IDE’s terminal (flatpack install), so to reproduce I guess using e.g. VScode terminal could be an option. As a workaround to use helgrind, simply execute in the “pure” terminal.
I have no idea what could be causing this. Does the IDE put something in the environment that affects glibc pthreads? Does the ISE use LD_PRELOAD or LD_LIBRARY_PATH to change the libs that get loaded?