Examples:
protected method example: protected methods can only be executed by one Thread at a time.
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php class ExampleThread extends Thread { public function run() { /* thread code */ if ( $this ->synchronized()) { } } protected function exclusive() { /* synchronized method */ } } $thread = new ExampleThread(); if ( $thread ->start()) { $thread ->exclusive(); } ?> |
private method example: private methods may only be executed by the Threaded object during execution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php class ExampleThread extends Thread { public function run() { /* thread code */ if ( $this ->insideonly()) { } } private function insideonly() { /* private method */ } } $thread = new ExampleThread(); if ( $thread ->start()) { $thread ->insideonly(); } ?> |
Please login to continue.