equal
deleted
inserted
replaced
|
1 function QVERIFY(x, debugInfo) { |
|
2 if (!(x)) { |
|
3 print(debugInfo); |
|
4 throw(debugInfo); |
|
5 } |
|
6 } |
|
7 |
|
8 var consumer = new ScriptSharedMemory; |
|
9 consumer.setKey("market"); |
|
10 |
|
11 //print("consumer starting"); |
|
12 var tries = 0;; |
|
13 while(!consumer.attach()) { |
|
14 if (tries == 5000) { |
|
15 var message = "consumer exiting, waiting too long"; |
|
16 print(message); |
|
17 throw(message); |
|
18 } |
|
19 ++tries; |
|
20 consumer.sleep(1); |
|
21 } |
|
22 //print("consumer attached"); |
|
23 |
|
24 |
|
25 var i = 0; |
|
26 while(true) { |
|
27 QVERIFY(consumer.lock(), "lock"); |
|
28 if (consumer.get(0) == 'Q') { |
|
29 consumer.set(0, ++i); |
|
30 //print ("consumer sets" + i); |
|
31 } |
|
32 if (consumer.get(0) == 'E') { |
|
33 QVERIFY(consumer.unlock(), "unlock"); |
|
34 break; |
|
35 } |
|
36 QVERIFY(consumer.unlock(), "unlock"); |
|
37 consumer.sleep(10); |
|
38 } |
|
39 |
|
40 //print("consumer detaching"); |
|
41 QVERIFY(consumer.detach()); |