qt5base-lts/tests/auto/qtipc/lackey/scripts/producer.js
Qt by Nokia 38be0d1383 Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you
want to look at revision history older than this, please refer to the
Qt Git wiki for how to use Git history grafting. At the time of
writing, this wiki is located here:

http://qt.gitorious.org/qt/pages/GitIntroductionWithQt

If you have already performed the grafting and you don't see any
history beyond this commit, try running "git log" with the "--follow"
argument.

Branched from the monolithic repo, Qt master branch, at commit
896db169ea224deb96c59ce8af800d019de63f12
2011-04-27 12:05:43 +02:00

44 lines
1.1 KiB
JavaScript

function QVERIFY(x, debugInfo) {
if (!(x)) {
print(debugInfo);
throw(debugInfo);
}
}
var producer = new ScriptSharedMemory;
producer.setKey("market");
var size = 1024;
if (!producer.create(size)) {
QVERIFY(producer.error() == 4, "create");
QVERIFY(producer.attach());
}
//print ("producer created and attached");
QVERIFY(producer.lock());
producer.set(0, 'Q');
QVERIFY(producer.unlock());
var i = 0;
while(i < 5) {
QVERIFY(producer.lock(), "lock");
if (producer.get(0) == 'Q') {
QVERIFY(producer.unlock(), "unlock");
producer.sleep(1);
continue;
}
//print("producer: " + i);
++i;
producer.set(0, 'Q');
QVERIFY(producer.unlock(), "unlock");
producer.sleep(1);
}
QVERIFY(producer.lock());
producer.set(0, 'E');
QVERIFY(producer.unlock());
//print ("producer done");
// Sleep for a bit to let all consumers start, otherwise they will get stuck in the attach loop,
// because at least in Symbian the shared memory will be destroyed if there are no active handles to it.
producer.sleep(3000);