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

Luke Blanshard blanshlu@netscape.net
Wed, 14 Jul 2004 10:38:53 -0400


No, there is nothing special about synchronizing a return statement.  It looks to me as if "hArray" is being used as the monitor for the "curr" instance variable, and so the sync block is making sure that "curr" is a valid index whenever that return statement gets its value out of the array.

Luke


"Booth, Peter" <Peter.Booth@gs.com> wrote:

>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;
>    }
>   }
>
>
>
>_______________________________________________
>Concurrency-interest mailing list
>Concurrency-interest@altair.cs.oswego.edu
>http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>

__________________________________________________________________
Switch to Netscape Internet Service.
As low as $9.95 a month -- Sign up today at http://isp.netscape.com/register

Netscape. Just the Net You Need.

New! Netscape Toolbar for Internet Explorer
Search from anywhere on the Web and block those annoying pop-ups.
Download now at http://channels.netscape.com/ns/search/install.jsp