mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-23 20:38:56 +00:00
86 lines
1.9 KiB
XML
86 lines
1.9 KiB
XML
![]() |
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<!-- $Revision: 297028 $ -->
|
||
|
|
||
|
<chapter xml:id="pthreads.modifiers" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||
|
<title>Method Modifiers</title>
|
||
|
<titleabbrev>Modifiers</titleabbrev>
|
||
|
<para>
|
||
|
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 Thread, Worker and Stackable objects from creation.
|
||
|
</para>
|
||
|
<example>
|
||
|
<title>protected method example: protected methods can only be executed by one Thread at a time.</title>
|
||
|
<programlisting role="php">
|
||
|
<![CDATA[
|
||
|
<?php
|
||
|
class ExampleThread extends Thread {
|
||
|
public function run() {
|
||
|
/* thread code */
|
||
|
if ($this->synchronized()) {
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
protected function synchronized() {
|
||
|
/* synchronized method */
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$thread = new ExampleThread();
|
||
|
if ($thread->start()) {
|
||
|
$thread->synchronized();
|
||
|
}
|
||
|
?>
|
||
|
]]>
|
||
|
</programlisting>
|
||
|
</example>
|
||
|
<example>
|
||
|
<title>private method example: private methods may only be executed by the Thread, Worker, or Stackable during execution</title>
|
||
|
<programlisting role="php">
|
||
|
<![CDATA[
|
||
|
<?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();
|
||
|
}
|
||
|
?>
|
||
|
]]>
|
||
|
</programlisting>
|
||
|
</example>
|
||
|
</chapter>
|
||
|
|
||
|
<!-- Keep this comment at the end of the file
|
||
|
Local variables:
|
||
|
mode: sgml
|
||
|
sgml-omittag:t
|
||
|
sgml-shorttag:t
|
||
|
sgml-minimize-attributes:nil
|
||
|
sgml-always-quote-attributes:t
|
||
|
sgml-indent-step:1
|
||
|
sgml-indent-data:t
|
||
|
indent-tabs-mode:nil
|
||
|
sgml-parent-document:nil
|
||
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
||
|
sgml-exposed-tags:nil
|
||
|
sgml-local-catalogs:nil
|
||
|
sgml-local-ecat-files:nil
|
||
|
End:
|
||
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
|
vim: et tw=78 syn=sgml
|
||
|
vi: ts=1 sw=1
|
||
|
-->
|
||
|
|