[concurrency-interest] What does it mean to synchronize "return x;" ?

Booth, Peter Peter.Booth@gs.com
Wed, 14 Jul 2004 09:58:55 -0400


I was looking at some code last night that did the following.

I was wondering - is there anything special about synchronizing a critical
section of code that is a return statement?

   private double []hArray;
   private int curr;

   public double getLast()
    {
        if (sMode ())
            synchronized(hArray)
            {
                return hArray [curr];
            }
        return last;
    }


   synchronized(hArray)
   {
   	double p = getLTP();
      for (int i = 0; i < hArray.length; i++)
      {
		hArray [i] = p;
      }
   	hArray [curr] = P2;
   	curr += 1;
   	if (curr >= hArray.length)
	{
      	curr = curr % hArray.length;
	}
   }