box86 icon indicating copy to clipboard operation
box86 copied to clipboard

A locking problem

Open ryancaicse opened this issue 3 years ago • 1 comments

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); 
 	} 

ryancaicse avatar Apr 05 '22 15:04 ryancaicse

Yeah, that would be better.

ptitSeb avatar Apr 05 '22 16:04 ptitSeb