tidy examples page

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@327810 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Joe Watkins 2012-09-26 17:19:20 +00:00
parent fb4f9b53fc
commit 99d2c44d4f

View file

@ -5,10 +5,10 @@
&reftitle.examples;
<section role="examples">
<para>This HelloWorld example demonstrates how simple it is to define and execute Threads in PHP applications.</para>
<example>
<title>Hello World Example</title>
<para>This HelloWorld example demonstrates how simple it is to define and execute Threads in PHP applications.</para>
<screen>
<programlisting role="php">
<![CDATA[
<?php
class HelloWorld extends Thread {
@ -28,13 +28,11 @@ if ($thread->start()) {
}
?>
]]>
</screen>
</programlisting>
</example>
</section>
<section role="examples">
<example>
<title>Synchronization</title>
<para>
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 ).
</para>
<screen>
<example>
<title>Synchronization</title>
<programlisting role="php">
<![CDATA[
<?php
class Task1 extends Thread {
@ -144,18 +144,16 @@ foreach ($tasks as $id => $task) {
/* ... */
?>
]]>
</screen>
</programlisting>
</example>
<para>
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.
</para>
</example>
</section>
<section role="examples">
<example>
<title>Mutex and Condition Variables</title>
<para>
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.
</para>
<screen>
<example>
<title>Mutex and Condition Variables</title>
<programlisting role="php">
<![CDATA[
<?php
/* ... */
@ -181,7 +181,8 @@ if (Cond::broadcast($finished)) {
}
?>
]]>
</screen>
</programlisting>
</example>
<para>
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.
</para>
<para>
<warning>
<para>
Before the programmer attempts to use Condition Variables they should have
@ -207,11 +209,10 @@ if (Cond::broadcast($finished)) {
risk of Spurious Wakeups.
</para>
</warning>
</example>
</para>
</section>
<section role="examples">
<example>
<title>Thread Members</title>
<para>
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.
</para>
<screen>
<example>
<programlisting role="php">
<![CDATA[
<?php
class ExampleThread extends Thread {
@ -258,7 +260,8 @@ if ($example->start()) {
}
?>
]]>
</screen>
</programlisting>
</example>
<para>
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.
</para>
</example>
</section>
</chapter>