box86
box86 copied to clipboard
A locking problem
Hi, should status = 0; at Line 55 be protected by locks from races?
https://github.com/ptitSeb/box86/blob/329ed0bb5b8b9e49e448fa8b471033403206ee3e/tests/test11.c#L43-L64
Just in this way.
if (pthread_self()==thread[0]) {
printf("Thread 1: Entered (%d/%d)\n", TLS_data1, TLS_data2);
} else {
while (!status) pthread_cond_wait(thread_state_cond_ptr, mutex_ptr);
printf("Thread 2: Entered (%d/%d)\n", TLS_data1, TLS_data2);
status = 0;
pthread_mutex_unlock(mutex_ptr);
pthread_cond_broadcast(thread_state_cond_ptr);
}
Yeah, that would be better.