示例#1
0
    public function run()
    {
        printf("%s: %lu running\n", __CLASS__, $this->getThreadId());
        foreach ($this->tests as $test) {
            /* this tests protected method access on a nonsense method, and reads some data directly */
            printf("%s: %lu working %lu ... %s/%d\n", __CLASS__, $this->getThreadId(), $test->getThreadId(), $test->my, $test->scopeTestFunc());
            /* this is us directly writing another threads members, just for something to do */
            $test->reading = rand() * 10 * microtime(true) / 10;
            /* tell the test thread we are done and it can read what was written now */
            $test->isFinished(true);
        }
        /* the process is waiting to handle failed tests */
        printf("%s: %lu notifying process: %d\n", __CLASS__, $this->getThreadId(), $this->notify());
    }
}
printf("Process: running\n");
$tests = array(new SyncTest(), new SyncTest());
$tester = new Tester($tests);
$tester->start();
$tester->wait();
printf("Process: notified\n");
foreach ($tests as $test) {
    if (!$test->isJoined() && $test->isWaiting()) {
        printf("Process: notifying %lu\n", $test->getThreadId());
        printf("Process: notified %lu: %d\n", $test->getThreadId(), $test->notify());
    } else {
        printf("Process: done with %lu\n", $test->getThreadId());
    }
    printf("Process: read %lu: %s\n", $test->getThreadId(), $test->reading);
}
printf("Process: notifying %lu\n", $tester->getThreadId());