Skip to content

Instantly share code, notes, and snippets.

@JavaDeveloper
Created October 4, 2012 14:13
Show Gist options
  • Save JavaDeveloper/3833765 to your computer and use it in GitHub Desktop.
Save JavaDeveloper/3833765 to your computer and use it in GitHub Desktop.
void* thread1_function(void* parameter){
pthread_mutex_lock(&lock1);
pthread_mutex_lock(&lock2); // DEADLOCK
...
...
pthread_mutex_lock(&lock2);
pthread_mutex_lock(&lock1);
}
void* thread2_function(void* parameter){
pthread_mutex_lock(&lock2);
pthread_mutex_lock(&lock1);
...
...
pthread_mutex_lock(&lock1);
pthread_mutex_lock(&lock2);
}
main(){
...
pthread_create(&thread1, NULL, thread1_function, NULL);
pthread_create(&thread2, NULL, thread2_function, NULL);
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment