Skip to content

Instantly share code, notes, and snippets.

@JavaDeveloper
Created October 4, 2012 14:28
Show Gist options
  • Save JavaDeveloper/3833866 to your computer and use it in GitHub Desktop.
Save JavaDeveloper/3833866 to your computer and use it in GitHub Desktop.
...
pthread_mutex_lock(&lock1);
while ( pthread_mutex_trylock(&lock2) ){
// Free resource to avoid deadlock
pthread_mutex_unlock(&lock1);
...
pthread_mutex_lock(&lock1);
}
count++;
pthread_mutex_unlock(&lock1);
pthread_mutex_unlock(&lock2);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment