lock and break

  • Thread starter Thread starter Franz
  • Start date Start date
F

Franz

Hi,

I have the following code.

while (foo) {
lock (bar) {
if (abc) {
break;
}
}
}

If I call the break statement, would the bar be unlocked?

Thanks.
Franz
 
Yes.

lock (x) {
// ... your code here
}

is equivalent to:

Monitor.Enter(x);
try {
// ... your code here
}
finally {
Monitor.Exit(x);
}

Frisky
 
Back
Top