Skip to content

A locking problem #604

@ryancaicse

Description

@ryancaicse

Hi, should status = 0; at Line 55 be protected by locks from races?

box86/tests/test11.c

Lines 43 to 64 in 329ed0b

void *thread_run(void *parm)
{
int rc;
threadparm_t *gData;
pthread_mutex_lock(mutex_ptr);
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);
pthread_mutex_unlock(mutex_ptr);
status = 0;
pthread_cond_broadcast(thread_state_cond_ptr);
}
gData = (threadparm_t *)parm;
/* Assign the value from global variable to thread specific variable*/
TLS_data1 = gData->data1;
TLS_data2 = gData->data2;
strcpy(TLS_data3, "---");

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions