Thanks for your reply. However, even after making it a var, I get complaint:

*Cannot access a non-static field field Test.currentWorkCounter:
x10.lang.Int from a static context
*
And to avoid it, I will have to make other two functions as non-static, but
then the whole program does not run properly and it complains:

*x10c++: No main method found
1 error.
*
Please help me, since I am not from Java background hence I am getting such
errors. Thanks.


Thanks and Regards
Sparsh Mittal



On Wed, Feb 13, 2013 at 4:07 PM, David P Grove <gro...@us.ibm.com> wrote:

>  Hi,
>
>  "val" roughly corresponds to "final" in Java (or const in C++)   To
> declare an instance field you want to be able to modify you need to use
> "var"
>
> var currentWorkCounter: Int =-1 ;
>
> --dave
>
>
> Sparsh Mittal <sparsh0mit...@gmail.com> wrote on 02/13/2013 12:11:46 PM:
>
> >
> > Hello
> > Here is the minimum working example of what I am trying to do. I
> > want to make currentWorkCounter a non-static member, which multiple
> > functions in the class can use and modify. However, compiler does
> > not allow. Can you please tell how to accomplish.
> >
> > //Does not compile due to non-static member.
> > import x10.io.Console;
> > import x10.lang.Int;
> >
> > public class Test {
> >
> > val currentWorkCounter: Int =-1 ;
> >
> > public  static def funcWorker (myNumber: Int) {
> >   val answer:Int;
> >
> >   atomic {
> >     currentWorkCounter =  currentWorkCounter +1;
> >     answer =currentWorkCounter;
> >   }
> >
> >   Console.OUT.println(myNumber+" did "+ answer);
> >
> > }
> >
> >   public static def main(args: Array[String](1)) {
> >
> >
> >       finish for(var k: Int =0; k< 5; k++) {
> >         val kk = k;
> >
> >         async funcWorker(kk );
> >          }
> >
> >          Console.OUT.println("I am done  " );
> >
> >
> >   }
> > }
> >
>
> > Thanks and Regards
> > Sparsh Mittal
> >
> ------------------------------------------------------------------------------
> > Free Next-Gen Firewall Hardware Offer
> > Buy your Sophos next-gen firewall before the end March 2013
> > and get the hardware for free! Learn more.
> > http://p.sf.net/sfu/sophos-d2d-feb
> > _______________________________________________
> > X10-users mailing list
> > X10-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
>
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to