On Thu, 10 Jun 2010 02:54:37 -0400, Kagamin <s...@here.lot> wrote:
> 
> Let's consider the following code:
> 
> synchronized(syncRoot)
> {
>   if(condition)opSuccess();
>   else writeln(possibly,slow);
> }
> 
> Suppose the else close doesn't need to be executed in lock domain and can be 
> slow. How to minimize lock time here?
> 
> synchronized(syncRoot)
> {
>   if(condition)opSuccess();
>   else goto Lwrite;
> }
> Lwrite: writeln(possibly,slow);
> 
> We can do this... but...

A common pattern is to use a boolean flag:

bool success;
synchronized (syncRoot)
{
  success = (condition);
}

if (success) opSuccess();
else writeln(possibly, slow);

Reply via email to