Skip to content

Possible data races without locking #127

@ycaibb

Description

@ycaibb

Hi, it seems the lock_handle should be protected by locks?

static int lock_handle;

void lock_stream() {
if (0 < lock_handle) {
flock(lock_handle, LOCK_EX);
}
pthread_mutex_lock(&thread_lock);
}
void unlock_stream() {
pthread_mutex_unlock(&thread_lock);
if (0 < lock_handle) {
flock(lock_handle, LOCK_UN);
}
}

Just like this.

 void lock_stream() { 
     pthread_mutex_lock(&thread_lock); 
     if (0 < lock_handle) { 
         flock(lock_handle, LOCK_EX); 
     } 
 } 
  
 void unlock_stream() { 
     if (0 < lock_handle) { 
         flock(lock_handle, LOCK_UN); 
     } 
     pthread_mutex_unlock(&thread_lock); 
 } 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions