Resolve deadlock / race conditions in philosophers
rm -f *.o
rm -f ./philosophers/*.o
rm -f ./producers_consumers/*.o
gcc -Iheaders -Wall -Werror -g -std=gnu99 -o "philosophers/"philosophers.o philosophers/src/philosophers.c -lcunit -lpthread
valgrind --tool=helgrind -s ./philosophers/philosophers.o 10
==59165== Helgrind, a thread error detector
==59165== Copyright (C) 2007-2017, and GNU GPL'd, by OpenWorks LLP et al.
==59165== Using Valgrind-3.17.0 and LibVEX; rerun with -h for copyright info
==59165== Command: ./philosophers/philosophers.o 10
==59165==
Philosopher 0 is thinking
Philosopher 0 is eating
Philosopher 0 is thinking
Philosopher 0 is eating
Philosopher 0 is thinking
Philosopher 0 is eating
Philosopher 0 is thinking
Philosopher 0 is eating
Philosopher 0 is thinking
Philosopher 0 is eating
==59165== ---Thread-Announcement------------------------------------------
==59165==
==59165== Thread #1 is the program's root thread
==59165==
==59165== ---Thread-Announcement------------------------------------------
==59165==
==59165== Thread #2 was created
==59165== at 0x49AC5D2: clone (in /usr/lib/libc-2.33.so)
==59165== by 0x4895261: create_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x4896A9D: pthread_create@@GLIBC_2.2.5 (in /usr/lib/libpthread-2.33.so)
==59165== by 0x4849237: pthread_create_WRK (hg_intercepts.c:436)
==59165== by 0x10957D: main (philosophers.c:62)
==59165==
==59165== ----------------------------------------------------------------
==59165==
==59165== Possible data race during write of size 1 at 0x4A7C3FD by thread #1
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10959A: main (philosophers.c:63)
==59165==
==59165== This conflicts with a previous write of size 1 by thread #2
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== Address 0x4a7c3fd is 13 bytes inside a block of size 1,024 alloc'd
==59165== at 0x4840805: malloc (vg_replace_malloc.c:380)
==59165== by 0x4922563: _IO_file_doallocate (in /usr/lib/libc-2.33.so)
==59165== by 0x4930DAF: _IO_doallocbuf (in /usr/lib/libc-2.33.so)
==59165== by 0x492FF67: _IO_file_overflow@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x492F015: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x49AC5E2: clone (in /usr/lib/libc-2.33.so)
==59165== Block was alloc'd by thread #2
==59165==
==59165== ----------------------------------------------------------------
==59165==
==59165== Possible data race during write of size 1 at 0x4A7C3FE by thread #1
==59165== Locks held: none
==59165== at 0x484F134: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919F55: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10959A: main (philosophers.c:63)
==59165==
==59165== This conflicts with a previous write of size 1 by thread #2
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== Address 0x4a7c3fe is 14 bytes inside a block of size 1,024 alloc'd
==59165== at 0x4840805: malloc (vg_replace_malloc.c:380)
==59165== by 0x4922563: _IO_file_doallocate (in /usr/lib/libc-2.33.so)
==59165== by 0x4930DAF: _IO_doallocbuf (in /usr/lib/libc-2.33.so)
==59165== by 0x492FF67: _IO_file_overflow@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x492F015: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x49AC5E2: clone (in /usr/lib/libc-2.33.so)
==59165== Block was alloc'd by thread #2
==59165==
==59165== ----------------------------------------------------------------
==59165==
==59165== Possible data race during write of size 1 at 0x4A7C3FF by thread #1
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10959A: main (philosophers.c:63)
==59165==
==59165== This conflicts with a previous write of size 1 by thread #2
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== Address 0x4a7c3ff is 15 bytes inside a block of size 1,024 alloc'd
==59165== at 0x4840805: malloc (vg_replace_malloc.c:380)
==59165== by 0x4922563: _IO_file_doallocate (in /usr/lib/libc-2.33.so)
==59165== by 0x4930DAF: _IO_doallocbuf (in /usr/lib/libc-2.33.so)
==59165== by 0x492FF67: _IO_file_overflow@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x492F015: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x49AC5E2: clone (in /usr/lib/libc-2.33.so)
==59165== Block was alloc'd by thread #2
==59165==
Create thread 0
Philosopher 1 is thinking
Philosopher 1 is eating
Philosopher 1 is thinking
Philosopher 1 is eating
Philosopher 1 is thinking
Philosopher 1 is eating
Philosopher 1 is thinking
Philosopher 1 is eating
Philosopher 1 is thinking
Philosopher 1 is eating
Create thread 1
Philosopher 2 is thinking
Philosopher 2 is eating
Philosopher 2 is thinking
Philosopher 2 is eating
Philosopher 2 is thinking
Philosopher 2 is eating
Philosopher 2 is thinking
Philosopher 2 is eating
Philosopher 2 is thinking
Philosopher 2 is eating
Create thread 2
Philosopher 3 is thinking
Philosopher 3 is eating
Philosopher 3 is thinking
Philosopher 3 is eating
Philosopher 3 is thinking
Philosopher 3 is eating
Philosopher 3 is thinking
Philosopher 3 is eating
Philosopher 3 is thinking
Philosopher 3 is eating
Create thread 3
Philosopher 4 is thinking
Philosopher 4 is eating
Philosopher 4 is thinking
Philosopher 4 is eating
Philosopher 4 is thinking
Philosopher 4 is eating
Philosopher 4 is thinking
Philosopher 4 is eating
Philosopher 4 is thinking
Philosopher 4 is eating
Create thread 4
Philosopher 5 is thinking
Philosopher 5 is eating
Philosopher 5 is thinking
Philosopher 5 is eating
Philosopher 5 is thinking
Philosopher 5 is eating
Philosopher 5 is thinking
Philosopher 5 is eating
Philosopher 5 is thinking
Philosopher 5 is eating
Create thread 5
Philosopher 6 is thinking
Philosopher 6 is eating
Philosopher 6 is thinking
Philosopher 6 is eating
Philosopher 6 is thinking
Philosopher 6 is eating
Philosopher 6 is thinking
Philosopher 6 is eating
Philosopher 6 is thinking
Philosopher 6 is eating
Create thread 6
Philosopher 7 is thinking
Philosopher 7 is eating
Philosopher 7 is thinking
Philosopher 7 is eating
Philosopher 7 is thinking
Philosopher 7 is eating
Philosopher 7 is thinking
Philosopher 7 is eating
Philosopher 7 is thinking
Philosopher 7 is eating
Create thread 7
Philosopher 8 is thinking
Philosopher 8 is eating
Philosopher 8 is thinking
Philosopher 8 is eating
Philosopher 8 is thinking
Philosopher 8 is eating
Philosopher 8 is thinking
Philosopher 8 is eating
Philosopher 8 is thinking
Philosopher 8 is eating
Create thread 8
Philosopher 9 is thinking
Philosopher 9 is eating
Philosopher 9 is thinking
Philosopher 9 is eating
Philosopher 9 is thinking
Philosopher 9 is eating
Philosopher 9 is thinking
Philosopher 9 is eating
Philosopher 9 is thinking
Philosopher 9 is eating
Create thread 9
==59165==
==59165== Use --history-level=approx or =none to gain increased speed, at
==59165== the cost of reduced accuracy of conflicting-access information
==59165== ERROR SUMMARY: 394 errors from 3 contexts (suppressed: 891 from 55)
==59165==
==59165== 19 errors in context 1 of 3:
==59165== ----------------------------------------------------------------
==59165==
==59165== Possible data race during write of size 1 at 0x4A7C3FE by thread #1
==59165== Locks held: none
==59165== at 0x484F134: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919F55: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10959A: main (philosophers.c:63)
==59165==
==59165== This conflicts with a previous write of size 1 by thread #2
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== Address 0x4a7c3fe is 14 bytes inside a block of size 1,024 alloc'd
==59165== at 0x4840805: malloc (vg_replace_malloc.c:380)
==59165== by 0x4922563: _IO_file_doallocate (in /usr/lib/libc-2.33.so)
==59165== by 0x4930DAF: _IO_doallocbuf (in /usr/lib/libc-2.33.so)
==59165== by 0x492FF67: _IO_file_overflow@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x492F015: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x49AC5E2: clone (in /usr/lib/libc-2.33.so)
==59165== Block was alloc'd by thread #2
==59165==
==59165==
==59165== 127 errors in context 2 of 3:
==59165== ----------------------------------------------------------------
==59165==
==59165== Possible data race during write of size 1 at 0x4A7C3FF by thread #1
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10959A: main (philosophers.c:63)
==59165==
==59165== This conflicts with a previous write of size 1 by thread #2
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== Address 0x4a7c3ff is 15 bytes inside a block of size 1,024 alloc'd
==59165== at 0x4840805: malloc (vg_replace_malloc.c:380)
==59165== by 0x4922563: _IO_file_doallocate (in /usr/lib/libc-2.33.so)
==59165== by 0x4930DAF: _IO_doallocbuf (in /usr/lib/libc-2.33.so)
==59165== by 0x492FF67: _IO_file_overflow@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x492F015: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x49AC5E2: clone (in /usr/lib/libc-2.33.so)
==59165== Block was alloc'd by thread #2
==59165==
==59165==
==59165== 248 errors in context 3 of 3:
==59165== ----------------------------------------------------------------
==59165==
==59165== Possible data race during write of size 1 at 0x4A7C3FD by thread #1
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10959A: main (philosophers.c:63)
==59165==
==59165== This conflicts with a previous write of size 1 by thread #2
==59165== Locks held: none
==59165== at 0x484F116: mempcpy (vg_replace_strmem.c:1562)
==59165== by 0x492EF8E: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x491970F: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== Address 0x4a7c3fd is 13 bytes inside a block of size 1,024 alloc'd
==59165== at 0x4840805: malloc (vg_replace_malloc.c:380)
==59165== by 0x4922563: _IO_file_doallocate (in /usr/lib/libc-2.33.so)
==59165== by 0x4930DAF: _IO_doallocbuf (in /usr/lib/libc-2.33.so)
==59165== by 0x492FF67: _IO_file_overflow@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x492F015: _IO_file_xsputn@@GLIBC_2.2.5 (in /usr/lib/libc-2.33.so)
==59165== by 0x4919225: __vfprintf_internal (in /usr/lib/libc-2.33.so)
==59165== by 0x49062DE: printf (in /usr/lib/libc-2.33.so)
==59165== by 0x10937E: think (philosophers.c:32)
==59165== by 0x109223: philosopher (philosophers.c:11)
==59165== by 0x4849436: mythread_wrapper (hg_intercepts.c:398)
==59165== by 0x4896258: start_thread (in /usr/lib/libpthread-2.33.so)
==59165== by 0x49AC5E2: clone (in /usr/lib/libc-2.33.so)
==59165== Block was alloc'd by thread #2
==59165==
--59165--
--59165-- used_suppression: 319 helgrind-glibc2X-005 /usr/lib/valgrind/default.supp:943
--59165-- used_suppression: 572 helgrind-glibc2X-004 /usr/lib/valgrind/default.supp:929
==59165==
==59165== ERROR SUMMARY: 394 errors from 3 contexts (suppressed: 891 from 55)```