Exemple #1
0
        echo "destr __ " . getmypid() . " \n";
        debug_print_backtrace();
        echo "___________________________\n";
    }
}
$g = new MyStuff();
class MyThread extends GPhpThread
{
    public function run()
    {
        echo 'Hello, I am a thread with id ' . $this->getPid() . "!\nTrying to lock the critical section\n";
        $lock = new GPhpThreadLockGuard($this->criticalSection);
        echo "=--- locked " . $this->getPid() . "\n";
        $this->criticalSection->addOrUpdateResource('IAM', $this->getPid());
        $this->criticalSection->addOrUpdateResource('IAMNOT', '0xdead1');
        $this->criticalSection->removeResource('IAMNOT');
        echo "=--- unlocked " . $this->getPid() . "\n";
        $this->setExitCode(8);
    }
}
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, false);
$thr1->start();
echo "Thread1 pid is: " . $thr1->getPid() . "\n";
$thr1->join();
echo "Thread 1 exit code: " . $thr1->getExitCode() . "\n";