helgrind doesn't like pthread.c and mice.c, even though the programs are correct and have no shared memory conflicts. helgrind finds no problems with pthread_cond.c, pthread_pipe.c, and mice-cond.c --- % pwd /home/perry/www/os/pthread % ls . .. Makefile NOTES pthread.c pthread_cond.c pthread_pipe.c % make gcc -std=c11 -pedantic -Wall -g -O -o pthread pthread.c -pthread gcc -std=c11 -pedantic -Wall -g -O -o pthread_cond pthread_cond.c -pthread gcc -std=c11 -pedantic -Wall -g -O -o pthread_pipe pthread_pipe.c -pthread % valgrind --tool=helgrind ./pthread ==9137== Helgrind, a thread error detector ==9137== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==9137== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==9137== Command: ./pthread ==9137== ==9137== ---Thread-Announcement------------------------------------------ ==9137== ==9137== Thread #2 was created ==9137== at 0x518460E: clone (clone.S:71) ==9137== by 0x4E4BEC4: create_thread (createthread.c:100) ==9137== by 0x4E4BEC4: pthread_create@@GLIBC_2.2.5 (pthread_create.c:797) ==9137== by 0x4C38A27: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9137== by 0x108887: main (pthread.c:28) ==9137== ==9137== ---Thread-Announcement------------------------------------------ ==9137== ==9137== Thread #1 is the program's root thread ==9137== ==9137== ---------------------------------------------------------------- ==9137== ==9137== Possible data race during write of size 4 at 0x309010 by thread #2 ==9137== Locks held: none ==9137== at 0x108832: f (pthread.c:16) ==9137== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9137== by 0x4E4B6DA: start_thread (pthread_create.c:463) ==9137== by 0x518461E: clone (clone.S:95) ==9137== ==9137== This conflicts with a previous read of size 4 by thread #1 ==9137== Locks held: none ==9137== at 0x1088C3: main (pthread.c:34) ==9137== Address 0x309010 is 0 bytes inside data symbol "count" ==9137== ==9137== ---------------------------------------------------------------- ==9137== ==9137== Possible data race during read of size 4 at 0x309010 by thread #1 ==9137== Locks held: none ==9137== at 0x1088C3: main (pthread.c:34) ==9137== ==9137== This conflicts with a previous write of size 4 by thread #2 ==9137== Locks held: none ==9137== at 0x108832: f (pthread.c:16) ==9137== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9137== by 0x4E4B6DA: start_thread (pthread_create.c:463) ==9137== by 0x518461E: clone (clone.S:95) ==9137== Address 0x309010 is 0 bytes inside data symbol "count" ==9137== ==9137== ---Thread-Announcement------------------------------------------ ==9137== ==9137== Thread #4 was created ==9137== at 0x518460E: clone (clone.S:71) ==9137== by 0x4E4BEC4: create_thread (createthread.c:100) ==9137== by 0x4E4BEC4: pthread_create@@GLIBC_2.2.5 (pthread_create.c:797) ==9137== by 0x4C38A27: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9137== by 0x108887: main (pthread.c:28) ==9137== ==9137== ---------------------------------------------------------------- ==9137== ==9137== Possible data race during read of size 4 at 0x309018 by thread #1 ==9137== Locks held: none ==9137== at 0x1088D0: main (pthread.c:34) ==9137== ==9137== This conflicts with a previous write of size 4 by thread #4 ==9137== Locks held: none ==9137== at 0x108832: f (pthread.c:16) ==9137== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9137== by 0x4E4B6DA: start_thread (pthread_create.c:463) ==9137== by 0x518461E: clone (clone.S:95) ==9137== Address 0x309018 is 8 bytes inside data symbol "count" ==9137== ==9137== ==9137== For counts of detected and suppressed errors, rerun with: -v ==9137== Use --history-level=approx or =none to gain increased speed, at ==9137== the cost of reduced accuracy of conflicting-access information ==9137== ERROR SUMMARY: 34 errors from 3 contexts (suppressed: 292 from 27) % valgrind --tool=helgrind ./pthread_cond ==9144== Helgrind, a thread error detector ==9144== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==9144== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==9144== Command: ./pthread_cond ==9144== ==9144== ==9144== For counts of detected and suppressed errors, rerun with: -v ==9144== Use --history-level=approx or =none to gain increased speed, at ==9144== the cost of reduced accuracy of conflicting-access information ==9144== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 22 from 15) % valgrind --tool=helgrind ./pthread_pipe ==9149== Helgrind, a thread error detector ==9149== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==9149== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==9149== Command: ./pthread_pipe ==9149== ==9149== ==9149== For counts of detected and suppressed errors, rerun with: -v ==9149== Use --history-level=approx or =none to gain increased speed, at ==9149== the cost of reduced accuracy of conflicting-access information ==9149== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 30 from 23) % make clean rm -f a.out core pthread pthread_cond pthread_pipe % cd ../Chapters/27-threads-api % gcc -Wall -o mice mice.c -pthread -lm % gcc -Wall -o mice-cond mice-cond.c -pthread -lm % valgrind --tool=helgrind ./mice > /dev/null ==9178== Helgrind, a thread error detector ==9178== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==9178== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==9178== Command: ./mice ==9178== ==9178== ---Thread-Announcement------------------------------------------ ==9178== ==9178== Thread #1 is the program's root thread ==9178== ==9178== ---Thread-Announcement------------------------------------------ ==9178== ==9178== Thread #2 was created ==9178== at 0x552260E: clone (clone.S:71) ==9178== by 0x51E9EC4: create_thread (createthread.c:100) ==9178== by 0x51E9EC4: pthread_create@@GLIBC_2.2.5 (pthread_create.c:797) ==9178== by 0x4C38A27: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x108B3B: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== ==9178== ---------------------------------------------------------------- ==9178== ==9178== Possible data race during read of size 4 at 0x30A0A0 by thread #1 ==9178== Locks held: none ==9178== at 0x108BA7: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== ==9178== This conflicts with a previous write of size 4 by thread #2 ==9178== Locks held: none ==9178== at 0x1089FB: play (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x108A6F: f (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x51E96DA: start_thread (pthread_create.c:463) ==9178== by 0x552261E: clone (clone.S:95) ==9178== Address 0x30a0a0 is 0 bytes inside data symbol "D" ==9178== ==9178== ---------------------------------------------------------------- ==9178== ==9178== Possible data race during read of size 8 at 0x30A0B0 by thread #1 ==9178== Locks held: none ==9178== at 0x108BF7: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== ==9178== This conflicts with a previous write of size 8 by thread #2 ==9178== Locks held: none ==9178== at 0x1089F2: play (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x108A6F: f (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x51E96DA: start_thread (pthread_create.c:463) ==9178== by 0x552261E: clone (clone.S:95) ==9178== Address 0x30a0b0 is 16 bytes inside data symbol "D" ==9178== ==9178== ---------------------------------------------------------------- ==9178== ==9178== Possible data race during write of size 4 at 0x30A0A0 by thread #1 ==9178== Locks held: none ==9178== at 0x108C27: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== ==9178== This conflicts with a previous write of size 4 by thread #2 ==9178== Locks held: none ==9178== at 0x1089FB: play (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x108A6F: f (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x51E96DA: start_thread (pthread_create.c:463) ==9178== by 0x552261E: clone (clone.S:95) ==9178== Address 0x30a0a0 is 0 bytes inside data symbol "D" ==9178== ==9178== ---------------------------------------------------------------- ==9178== ==9178== Possible data race during read of size 4 at 0x30A0A0 by thread #2 ==9178== Locks held: none ==9178== at 0x1089E3: play (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x108A6F: f (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x51E96DA: start_thread (pthread_create.c:463) ==9178== by 0x552261E: clone (clone.S:95) ==9178== ==9178== This conflicts with a previous write of size 4 by thread #1 ==9178== Locks held: none ==9178== at 0x108C27: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== Address 0x30a0a0 is 0 bytes inside data symbol "D" ==9178== ==9178== ---------------------------------------------------------------- ==9178== ==9178== Possible data race during write of size 8 at 0x30A0B0 by thread #2 ==9178== Locks held: none ==9178== at 0x1089F2: play (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x108A6F: f (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x51E96DA: start_thread (pthread_create.c:463) ==9178== by 0x552261E: clone (clone.S:95) ==9178== ==9178== This conflicts with a previous read of size 8 by thread #1 ==9178== Locks held: none ==9178== at 0x108BF7: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== Address 0x30a0b0 is 16 bytes inside data symbol "D" ==9178== ==9178== ---------------------------------------------------------------- ==9178== ==9178== Possible data race during write of size 4 at 0x30A0A0 by thread #2 ==9178== Locks held: none ==9178== at 0x1089FB: play (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x108A6F: f (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== by 0x4C38C26: ??? (in /usr/lib/valgrind/vgpreload_helgrind-amd64-linux.so) ==9178== by 0x51E96DA: start_thread (pthread_create.c:463) ==9178== by 0x552261E: clone (clone.S:95) ==9178== ==9178== This conflicts with a previous write of size 4 by thread #1 ==9178== Locks held: none ==9178== at 0x108C27: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== Address 0x30a0a0 is 0 bytes inside data symbol "D" ==9178== ==9178== ==9178== More than 10000000 total errors detected. I'm not reporting any more. ==9178== Final error counts will be inaccurate. Go fix your program! ==9178== Rerun with --error-limit=no to disable this cutoff. Note ==9178== that errors may occur in your program without prior warning from ==9178== Valgrind, because errors are no longer being displayed. ==9178== ^C ==9178== ==9178== Process terminating with default action of signal 2 (SIGINT) ==9178== at 0x5504DD5: sched_yield (syscall-template.S:78) ==9178== by 0x108B89: main (in /home/perry/www/os/Chapters/27-threads-api/mice) ==9178== ==9178== For counts of detected and suppressed errors, rerun with: -v ==9178== Use --history-level=approx or =none to gain increased speed, at ==9178== the cost of reduced accuracy of conflicting-access information ==9178== ERROR SUMMARY: 10000000 errors from 6 contexts (suppressed: 0 from 0) % valgrind --tool=helgrind ./mice-cond > /dev/null ==9189== Helgrind, a thread error detector ==9189== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al. ==9189== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info ==9189== Command: ./mice-cond ==9189== ==9189== ==9189== For counts of detected and suppressed errors, rerun with: -v ==9189== Use --history-level=approx or =none to gain increased speed, at ==9189== the cost of reduced accuracy of conflicting-access information ==9189== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 1262580 from 54) %