Skip to content

Instantly share code, notes, and snippets.

@gustavoanatoly
Created October 17, 2012 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavoanatoly/3906907 to your computer and use it in GitHub Desktop.
Save gustavoanatoly/3906907 to your computer and use it in GitHub Desktop.
deadlock; recursive lock
/*
* call-seq:
* mutex.try_lock -> true or false
*
* Attempts to obtain the lock and returns immediately. Returns +true+ if the
* lock was granted.
*/
VALUE
rb_mutex_trylock(VALUE self) {
/*
* line 3936
*/
if (rb_mutex_trylock(self) == Qfalse) {
rb_mutex_t *mutex;
rb_thread_t *th = GET_THREAD();
GetMutexPtr(self, mutex);
if (mutex->th == GET_THREAD()) {
rb_raise(rb_eThreadError, "deadlock; recursive locking");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment