equal
deleted
inserted
replaced
35 var obj = { |
35 var obj = { |
36 count: 0, |
36 count: 0, |
37 // Sync called with one argument will synchronize on this-object of invocation |
37 // Sync called with one argument will synchronize on this-object of invocation |
38 inc: sync(function(d) { |
38 inc: sync(function(d) { |
39 this.count += d; |
39 this.count += d; |
|
40 Assert.assertTrue(java.lang.Thread.holdsLock(this)); |
40 }), |
41 }), |
41 // Pass explicit object to synchronize on as second argument |
42 // Pass explicit object to synchronize on as second argument |
42 dec: sync(function(d) { |
43 dec: sync(function(d) { |
43 this.count -= d; |
44 this.count -= d; |
|
45 Assert.assertTrue(java.lang.Thread.holdsLock(obj)); |
44 }, obj) |
46 }, obj) |
45 }; |
47 }; |
46 |
48 |
47 var t1 = new java.lang.Thread(function() { |
49 var t1 = new java.lang.Thread(function() { |
48 for (var i = 0; i < 100000; i++) obj.inc(1); |
50 for (var i = 0; i < 100000; i++) obj.inc(1); |