TommyJD93 / Philosophers

Dining philosophers problem's guide for 42 school
91 stars 4 forks source link

Data races and philosopher dies when we make 200 threads #2

Open vasilisalmpanis opened 1 year ago

vasilisalmpanis commented 1 year ago

Compiling with -fsanitize=thread gives the following error on the school mac

WARNING: ThreadSanitizer: data race (pid=2438)
  Write of size 4 at 0x7ffee1d15760 by thread T54 (mutexes: write M244, write M16):
    \#0 messages <null>:2 (philo:x86_64+0x1000038bc)
    #1 supervisor <null>:2 philo:x86_64+0x1000030fa)

  Previous read of size 4 at 0x7ffee1d15760 by thread T10:
    \#0 supervisor <null>:2 (philo:x86_64+0x10000306a)

  Location is stack of main thread.

  Mutex M244 (0x7ba800000c58) created at:
    \#0 pthread_mutex_init <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2e913)
    \#1 init_philos <null>:2 (philo:x86_64+0x1000022a1)
    \#2 init <null>:2 (philo:x86_64+0x10000274e)
    \#3 main <null>:2 (philo:x86_64+0x1000019ab)

  Mutex M16 (0x7ffee1d157d8) created at:
    \#0 pthread_mutex_init <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2e913)
    \#1 init_data <null>:2 (philo:x86_64+0x10000265d)
    \#2 init <null>:2 (philo:x86_64+0x1000026f4)
    \#3 main <null>:2 (philo:x86_64+0x1000019ab)

  Thread T54 (tid=91819, running) created by thread T53 at:
    \#0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2d8fd)
    \#1 routine <null>:2 (philo:x86_64+0x100003334)

  Thread T10 (tid=91775, running) created by thread T9 at:
    \#0 pthread_create <null>:3 (libclang_rt.tsan_osx_dynamic.dylib:x86_64h+0x2d8fd)
    \#1 routine <null>:2 (philo:x86_64+0x100003334)

SUMMARY: ThreadSanitizer: data race (philo:x86_64+0x1000038bc) in messages+0x16c
==================
ThreadSanitizer: reported 1 warnings
[1]    2438 abort      ./philo 200 800 200 200

also when running the below prompt : ./philo 200 800 200 200 a philosopher dies but he is not supposed to according to the subject.

TommyJD93 commented 11 months ago

Sorry for the late response. Right now I'm kinda busy with the 42 common core so I don't have much time to review this "old" code. But I will asap. Apologies if I couldn't help you out. And thanks for the issue :)

vasilisalmpanis commented 11 months ago

Hey. No worries i just pointed out that the project is not working as it should according to the subject. Have a nice day