equal
deleted
inserted
replaced
|
1 function QVERIFY(x, debugInfo) { |
|
2 if (!(x)) { |
|
3 print(debugInfo); |
|
4 throw(debugInfo); |
|
5 } |
|
6 } |
|
7 |
|
8 var producer = new ScriptSharedMemory; |
|
9 producer.setKey("market"); |
|
10 |
|
11 var size = 1024; |
|
12 if (!producer.create(size)) { |
|
13 QVERIFY(producer.error() == 4, "create"); |
|
14 QVERIFY(producer.attach()); |
|
15 } |
|
16 //print ("producer created and attached"); |
|
17 |
|
18 QVERIFY(producer.lock()); |
|
19 producer.set(0, 'Q'); |
|
20 QVERIFY(producer.unlock()); |
|
21 |
|
22 var i = 0; |
|
23 while(i < 5) { |
|
24 QVERIFY(producer.lock(), "lock"); |
|
25 if (producer.get(0) == 'Q') { |
|
26 QVERIFY(producer.unlock(), "unlock"); |
|
27 producer.sleep(1); |
|
28 continue; |
|
29 } |
|
30 //print("producer: " + i); |
|
31 ++i; |
|
32 producer.set(0, 'Q'); |
|
33 QVERIFY(producer.unlock(), "unlock"); |
|
34 producer.sleep(1); |
|
35 } |
|
36 QVERIFY(producer.lock()); |
|
37 producer.set(0, 'E'); |
|
38 QVERIFY(producer.unlock()); |
|
39 |
|
40 //print ("producer done"); |
|
41 |
|
42 // Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop, |
|
43 // because at least in Symbian the shared memory will be destroyed if there are no active handles to it. |
|
44 producer.sleep(3000); |