-
-
Notifications
You must be signed in to change notification settings - Fork 249
Closed
Description
Hi, should status = 0; at Line 55 be protected by locks from races?
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);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels