Jim LaGrone wrote:
> If I have the following:
>
> arry = Array.makeVar[type](region, ((p):Point => new type());
> finish foreach( i in dist ){
> ...loop... stuff
> }
>
>
Here is what the above piece of code does. It creates a single array,
arry, with one point for each region, initialized with an execution of
new type().
Each array element is mutable and is shared between all activities that
can access arry.
> how does is change with the array creation inside the loop?
>
> finish foreach( i in dist ){
> arry = Array.makeVar[type](region, ((p):Point => new type());
> ...loop... stuff
> }
>
>
This, on the other hand, creates an activity for each i in dist. All
these activities run simultaneously.
Each activity creates an array and assigns it to arry.
Now how is arry declared? For the above code to compile, arry has to be
declared to be a local variable within the foreach loop, i.e. the code
has to look like
finish foreach( i in dist ){
val arry = Array.makeVar[type](region, ((p):Point => new type());
...loop... stuff
}
In this case arry is going to stay private to each activity generated by
the foreach -- unless and until the code in the body of the loop lets it
escape (e.g. by assigning arry to the field of an object shared with
some other activities).
Hope this helps.
Best,
Vijay
------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users