Compare commits

...

1 commit

Author SHA1 Message Date
e9b4f8e389 mutex(fix): prevent race condition (part 2)
In addition to the previous commit, this commit makes threads need to
wait for the thread manager to say it took the mutex from them before
they can ask for it again.
2024-11-19 15:12:42 -08:00

View file

@ -56,9 +56,10 @@ void *thread_task_increment(const struct thread_data &thread) {
{
// tell the thread manager we want the mutex
while (!*thread.manager_took_mutex)
(*thread.wants_mutex) = true;
// block until we have the mutex
while (!*thread.has_mutex && *thread.manager_took_mutex)
while (!*thread.has_mutex)
;
// enter the mutex