I am new to X10, coming from many years of C++ and Java. Trying to understand
how to properly use atomic blocks for the synchronization tasks.
In my Java experience, I often use synchronized methods or blocks, so the
object is used as monitor. This way, if I have multiple objects of the same
class, then different threads can update different objects concurrently.
Now, in X10, it is not a good idea to just translate the synchronized methods
to atomic blocks, because then only one object can be updated at a time
(assuming all my objects live in the same place).
So, to solve this problem should I do something like this:
..................................
var busy : Boolean = False;
def update(... some arguments ....) {
when(!busy) {
busy = True;
}
/* update code here */
............................
atomic {
busy = False;
}
}
.....................................
This way it becomes sort of equivalent to Java synchronization, with boolean
variable serving as a monitor. The time of the activity in atomic block is
minimal.
Now I have a couple of questions.
1. Is the example above the correct way to do it? Is there any other way?
2. Looks like this approach may cause a classical deadlock, if in one method it
checks for "busy1" and then "busy2", and in the other method "busy2" and then
"busy1". This means that X10 promise of no deadlocks is not quite true. There
no deadlocks if you program is correct, but this you can say about Java too,
and any other language.
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users