diff --git a/reference/pthreads/examples.xml b/reference/pthreads/examples.xml index 4154ff67a2..2d0d8518ff 100644 --- a/reference/pthreads/examples.xml +++ b/reference/pthreads/examples.xml @@ -5,10 +5,10 @@ &reftitle.examples;
+ This HelloWorld example demonstrates how simple it is to define and execute Threads in PHP applications. Hello World Example - This HelloWorld example demonstrates how simple it is to define and execute Threads in PHP applications. - + start()) { } ?> ]]> - +
- - Synchronization The purpose of PHP is to generate content, having Threading in the toolbox makes more content available. But content is a relative subject, for this @@ -96,7 +94,9 @@ if ($thread->start()) { to execute, or forced to wait, to allow flexible, powerful multi-threading whether being used for a Search Engine or Administration ( ie. cron jobs ). - + + Synchronization + $task) { /* ... */ ?> ]]> - + + Using the wait/notify mechanism included in pthreads hides the complexity of using Mutex and Condition Variables to synchronize Threads, greatly simplifies readability and more importantly maintainability of an idea or implementation. -
- - Mutex and Condition Variables pthreads allows direct access to ( a subset of ) both of these features. The programmer should take care to destroy Mutex and Condition Variable @@ -171,7 +169,9 @@ foreach ($tasks as $id => $task) { Mutex and Condition Variables persist once allocated until they are explicitly destroyed. - + + Mutex and Condition Variables + ]]> - + + The snippet above shows a PHP script sending it's final broadcast to the Threads it has created and cleaning up the Condition Variable it created and used for @@ -189,6 +190,7 @@ if (Cond::broadcast($finished)) { using $signals - waiting for a signal always requires a Mutex - and as the Condition Variable is no longer valid, the accompanying Mutex is also destroyed. + Before the programmer attempts to use Condition Variables they should have @@ -207,11 +209,10 @@ if (Cond::broadcast($finished)) { risk of Spurious Wakeups. - +
- Thread Members The members of a Thread can be of any type that PHP supports the serialization @@ -227,7 +228,8 @@ if (Cond::broadcast($finished)) { before the newly created context executes Thread::run. This results in correct deserialization of the programmer declared type in the new context. - + + start()) { } ?> ]]> - + + In the example above, /path/to/inc.php declares a class, as defined by the programmer. The programmer includes the declaration in the global scope @@ -266,7 +269,6 @@ if ($example->start()) { The instance of ExampleThread is able to manipulate the object and execute member functions having included the declaration using __prepare magic. -