Hi, I want to simulate the Java 'synchronized' methods in X10, so what I did is to add a lock to the object. As shown in the attached source code below, the 'syncIncr()' method is expected to yield a good performance. The problem is that I am not getting a good result here:
Profile result: t(b) =38273 // 38 us t(s) =693384 // 693 us Any suggestions to improve the program? Source code: 1 public class TestLock { 2 public static class Counter { 3 private var c:int; 4 private val lock:Lock; 5 public def this() { 6 c = 0; 7 lock = new Lock(); 8 } 9 10 public def incr() { 11 this.c = this.c + 1; 12 } 13 14 public def syncIncr() { 15 lock.lock(); 16 this.c = this.c + 1; 17 lock.unlock(); 18 } 19 } 20 21 public static def main(Array[String](1)) { 22 val o = new Counter(); 23 24 var t:Long = -System.nanoTime(); 25 for (var i:int=0; i < 10000; i++) { 26 o.incr(); 27 } 28 29 t += System.nanoTime(); 30 Console.ERR.println(" t(b) =" + t); 31 32 var t1:Long = -System.nanoTime(); 33 for (var i:int=0; i < 10000; i++) { 34 o.syncIncr(); 35 } 36 t1 += System.nanoTime(); 37 Console.ERR.println(" t(s) =" + t1); 38 } 39 } Regards, - Qiming ------------------------------------------------------------------------------ Gaining the trust of online customers is vital for the success of any company that requires sensitive data to be transmitted over the Web. Learn how to best implement a security strategy that keeps consumers' information secure and instills the confidence they need to proceed with transactions. http://p.sf.net/sfu/oracle-sfdevnl _______________________________________________ X10-users mailing list X10-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/x10-users