echo "=--- locked " . $this->getPid() . "\n"; $this->criticalSection->addOrUpdateResource('IAM', $this->getPid()); $this->criticalSection->addOrUpdateResource('IAMNOT', '0xdead1'); $this->criticalSection->removeResource('IAMNOT'); while (!$this->criticalSection->unlock()) { $this->sleep(200000); } echo "=--- unlocked " . $this->getPid() . "\n"; } } } echo "Master main EP " . getmypid() . "\n"; $criticalSection = new GPhpThreadCriticalSection(); $criticalSection->cleanPipeGarbage(); // remove any garbage left from any ungracefully terminated previous executions echo "\nLaunching Thread1...\n\n"; $thr1 = new MyThread($criticalSection, true); $thr1->start(); $thr1->join(); echo "\n---Thread1 id was: " . $criticalSection->getResourceValueFast('IAM') . "---\n"; echo "Master after the join of Thread1.\n\n"; echo "\nLaunching Thread2...\n\n"; $thr2 = new MyThread($criticalSection, true); $thr2->start(); $thr2->join(); echo "---Thread2 id was: " . $criticalSection->getResourceValueFast('IAM') . "---\n"; echo "Master after the join of Thread2.\n\n"; echo "\n\nThe resources that left in the critical section:\n"; var_dump($criticalSection->getResourceNames()); $thr1 = null; $thr2 = null;