Php/docs/pthreads.modifiers

提供:Dev Guides
< Php
2020年12月14日 (月) 12:25時点におけるNotes (トーク | 投稿記録)による版 (autoload)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

Method Modifiers

警告 These semantics are only applicable to pthreads v2 - they have been removed in pthreads v3.


pthreads overrides the functionality of the protected and private method modifiers in order to provide functionality more suited to multi-threaded objects. pthreads applies this functionality to all Threaded objects from creation.

例1 protected method example: protected methods can only be executed by one Thread at a time.

<?phpclass ExampleThread extends Thread {    public function run() {        /* thread code */        if ($this->synchronized()) {        }    }    protected function exclusive() {        /* synchronized method */    }}$thread = new ExampleThread();if ($thread->start()) {    $thread->exclusive();}?>

例2 private method example: private methods may only be executed by the Threaded object during execution

<?phpclass ExampleThread extends Thread {    public function run() {        /* thread code */        if ($this->insideonly()) {        }    }    private function insideonly() {        /* private method */    }}$thread = new ExampleThread();if ($thread->start()) {    $thread->insideonly();}?>