Great!

X10 has similar try-catch-finally block. It's explained in 12.17 of the
specification.

Thank you,
Saliya


On Fri, Nov 16, 2012 at 12:15 PM, LEONID ILYEVSKY
<leonidilyev...@yahoo.com>wrote:

> Thanks Saliya, this makes sense. It does solve the problem. Though it is
> not high level construct like Java's 'synchronized", it is a small price to
> pay for the benefit of no-deadlock guarantee.
> The only concern now is, I have to make sure that the activity that sets
> inUse will ultimately unset it.  What I mean is, some exception may happen
> inside the method, so I need to learn how to implement behavior similar to
> Java's "finally" block.
>
>   ------------------------------
> *From:* Saliya Ekanayake <esal...@gmail.com>
> *To:* LEONID ILYEVSKY <leonidilyev...@yahoo.com>
> *Cc:* Mailing list for users of the X10 programming language <
> x10-users@lists.sourceforge.net>
> *Sent:* Friday, November 16, 2012 11:51 AM
>
> *Subject:* Re: [X10-users] Atomic blocks
>
> A small correction to what I sent earlier. The last operation should be
> inside an atomic block too.
>
> when (! inUse) {
>   inUse = true;
> }
>
> m( ); // the time consuming operation
>
> atomic {
>   inUse = false;
> }
>
>
>
> On Fri, Nov 16, 2012 at 11:47 AM, Saliya Ekanayake <esal...@gmail.com>wrote:
>
> Btw. you may find the X10 language specification useful as well
> http://x10.sourceforge.net/documentation/languagespec/x10-230.pdf
>
> Thanks,
> Saliya
>
>
> On Fri, Nov 16, 2012 at 11:45 AM, Saliya Ekanayake <esal...@gmail.com>wrote:
>
> Thank you, I see what you meant now.
>
> Yes, it seems all atomic operations in one place is handled with an
> exclusive lock. So as a workaround will something like this work,
>
> In your class having a boolean variable, say *inUse *which is initially *
> false*. Then you will implement your method without specifying as an
> atomic method, say *m( )*
> *
> *
> Now having an entry and exit atomic sections like,
>
> when (! inUse) {
>   inUse = true;
> }
>
> m( ); // the time consuming operation
> inUse = false;
>
> Thank you,
> Saliya
>
>
>
>
>
>
> On Fri, Nov 16, 2012 at 10:59 AM, LEONID ILYEVSKY <
> leonidilyev...@yahoo.com> wrote:
>
> Saliya,
>
> Thanks for your reply.
> Let me clarify my question. This situation, I believe, is pretty common
> actually.
>
> So I have multiple objects of the same class. The methods are made
> synchronized because they update the objects' data based on the previous
> values and some information read from, let say, files or database. Such
> operation may take some time, and it is important that two different
> instances may be processed in parallel.
> On the other hand, if two threads try to update the same object, then only
> one at a time can be allowed, the other thread(s) must wait.
> So, in Java this is achieved simply by declaring methods synchronized, and
> then I safely can have a pool of threads doing the work, efficiently
> utilizing resources, and be sure that no data corruption happens.
>
> I am reading now http://www.cs.rice.edu/~vs3/PDF/pmup06.pdf , and it says
> that currently atomic behavior is implemented by an exclusive lock on the
> place. This means that parallel operation as described in my java example
> will be impossible in X10. I understand that this approach helps to make
> sure that deadlock never happens.
>
> However, real life applications may require more parallelizm. For example,
> the classical textbook banking application. I withdraw my money from the
> ATM, at the same time the back office application is trying to apply direct
> deposit to my account. These operations must be syncronized, but operations
> on othe client's accounts can be applied at the same time, they don't have
> to wait.
>
>
>
>    ------------------------------
> *From:* Saliya Ekanayake <esal...@gmail.com>
> *To:* LEONID ILYEVSKY <leonidilyev...@yahoo.com>; Mailing list for users
> of the X10 programming language <x10-users@lists.sourceforge.net>
> *Sent:* Friday, November 16, 2012 10:38 AM
> *Subject:* Re: [X10-users] Atomic blocks
>
> Hi Leonid,
>
> In your java version, are the threads accessing a separate copy of your
> object? If so it seems like it should work even without being a
> synchronized method. Also, if you create multiple objects and access them
> from separate activities in X10 they should not block and atomic may not
> make any difference as I understand.
>
> In fact, atomic usage is beneficial only when you have a critical section
> that at a given time only one activity is allowed to be in (per place).
>
> Hope this helps.
>
> Thank you,
> Saliya
>
>
> On Fri, Nov 16, 2012 at 10:28 AM, LEONID ILYEVSKY <
> leonidilyev...@yahoo.com> wrote:
>
> Hi,
>
> I am new to X10, and I have a question about the atomic construct, maybe
> somebody can clarify it for me.
>
> Let say, in Java I have a class with some synchronized (on the object
> level) methods. If I have 100 such objects in memory, then 100 threads can
> simultaneously work on those objects without blocking each other.
> How you do the same thing in X10 (asuming the program is running in one
> place)? From the definition of the atomic block, it seems that if I
> translate Java syncronized methods to X10 atomic methods, then only one
> object at a time can be processed. Is my understanding correct?
>
>
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com
>
>
>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com
>
>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com
>
>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com
>
>
>


-- 
Saliya Ekanayake
http://www.esaliya.blogspot.com
http://www.esaliya.wordpress.com
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to