Created
March 12, 2012 10:42
-
-
Save peterdn/2021105 to your computer and use it in GitHub Desktop.
Re-entrant locking vs blocking
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A | |
{ | |
private object _lock = new object(); | |
public void foo() | |
{ | |
lock(_lock) | |
{ | |
do_something(); | |
} | |
} | |
public void bar() | |
{ | |
lock(_lock) | |
{ | |
while(condition) | |
foo(); | |
do_something_else(); | |
} | |
} | |
} | |
class B | |
{ | |
private object _lock = new object(); | |
private void foo_have_lock() | |
{ | |
do_something(); | |
} | |
public void foo() | |
{ | |
lock(_lock) | |
{ | |
foo_have_lock(); | |
} | |
} | |
public void bar() | |
{ | |
lock(_lock) | |
{ | |
while(condition) | |
foo_have_lock(); | |
do_something_else(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment