Sorry, now I see Saliya already suggested this solution back in November.
So I wonder, woudn't it make sense to have this behavior wrapped in a construct
similar to Java's "synchronized"?
Of course, this will bring back the danger of the deadlock.
________________________________
From: LEONID ILYEVSKY <leonidilyev...@yahoo.com>
To: Mailing list for users of the X10 programming language
<x10-users@lists.sourceforge.net>; Saliya Ekanayake <esal...@gmail.com>
Sent: Thursday, April 11, 2013 1:12 PM
Subject: Re: [X10-users] Atomic blocks
After some idle time, I got back to my x10 study.
Now I think this is the solution for my question, please tell me if it is
correct.
public class Account(name:String) {
private var balance:Double = 0;
private var open:Boolean =
true;
def this(name:String) {
property(name);
}
public def change(x:Double) {
when(open) open = false;
balance = balance + x;
// Do more things here ....
atomic open = true;
}
public def getBalance() : Double = balance;
}
The focus point here is the "change" method. The boolean flag "open" is
accessed only in atomic blocks. The main logic piece "balance = balance + x"
is not in atomic block, but for a given instance of Account it may be accessed
only by one activity at a time. Different instances, however, may be processed
simultaneously
by different activities.
The global blocking is minimized to a simple assignment to the flag. This sort
of thing is necessary anyway in any multithreading system.
________________________________
From: LEONID ILYEVSKY <leonidilyev...@yahoo.com>
To: Saliya Ekanayake <esal...@gmail.com>
Cc: Mailing list for users of the X10 programming language
<x10-users@lists.sourceforge.net>
Sent: Friday, November 16, 2012 11:48 PM
Subject: Re: [X10-users] Atomic blocks
I would guess, the "when(B)" is implemented using Java wait-notify framework,
or similar mechanism, something like:
// Acquire the lock
synchronized(<the place-global lock>) {
while(!B) {
wait(); // At this point it releases the place-global
lock, and so other threads can enter the same piece of code for
the different instance of B
}
B = true;
}
...................
// release the lock
synchronized(<the place-global lock>) {
B = true;
notify();
}
On 11/16/2012 5:32 PM, Saliya Ekanayake wrote:
As far as I understand, the locking for when(B) S code should be similar atomic
S. So if one activity is checking the condition in when(B) S in one object all
other activities trying to check it will block irrespective to on what
instances they check.
>
>
>However, I too thought it should not add a considerable overhead as the
>blocking happens to on a quick test and set.
>
>
>
>
>Thank you,
>Saliya
>
>
>
>On Fri, Nov 16, 2012 at 5:03 PM, LEONID ILYEVSKY <leonidilyev...@yahoo.com>
>wrote:
>
>Now I don't quite understand. Setting the flag is quick, therefore many
>activities can work in parallel on multiple objects between setting and
>unsetting the flag. Only some activities will have to wait if they want to
>access the object that is currently busy.
>>Or am I missing something here? If one activity is waiting for the busy one
>>at the "when" statement, does it affect another activity which is checking
>>different instance of the flag? If that other instance is not busy, can it
>>enter the "when" block?
>>
>>
>>
>>
>>________________________________
>> From: Saliya Ekanayake <esal...@gmail.com>
>>
>>To: Mailing list for users of the X10 programming language
>><x10-users@lists.sourceforge.net>
>>Sent: Friday, November 16, 2012 4:43 PM
>>
>>Subject: Re: [X10-users] Atomic blocks
>>
>>
>>
>>Yes I agree, that in the workaround I posted, setting the flag is still be
>>dependent on the single lock.
>>
>>
>>I wonder if there's some documentation to x10.util.concurrent package?
>>
>>
>>Thank you,
>>Saliya
>>
>>
>>
>>On Fri, Nov 16, 2012 at 4:09 PM, Vijay Saraswat <vi...@saraswat.org> wrote:
>>
>>On 11/16/12 3:58 PM, LEONID ILYEVSKY wrote:
>>>
>>>Saliya suggested to use boolean flag to guard the critical session, set it
>>>in the "when" block and unset it in "atomic". Looks like a solution
>>>virtually equivalent to java's synchronization. What do you think?
>>>>
>>>>
>>>>
>>>>
This wont give the performance you want because of the current
single-lock-per-place implementation (see Dave Cunningham's message).
>>>
>>>------------------------------------------------------------------------------
>>>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
>>
>>------------------------------------------------------------------------------
>>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
>>
>>
>>
>>------------------------------------------------------------------------------
>>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
>
------------------------------------------------------------------------------
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
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users