diff --git a/reference/pthreads/book.xml b/reference/pthreads/book.xml index d49e0c758e..23b98c3f5b 100644 --- a/reference/pthreads/book.xml +++ b/reference/pthreads/book.xml @@ -10,11 +10,15 @@ pthreads is an Object Orientated API that allows user-land multi-threading in PHP. It includes all the tools you need to create multi-threaded applications targeted at the Web or the Console. - PHP applications can create, read, write, execute and synchronize with Threads, Workers and Stackables. + PHP applications can create, read, write, execute and synchronize with Threads, Workers and Threaded objects. - A Thread Object: - The user can implement a thread by extending the Thread declaration provided by pthreads. + A Threaded Object: + A Threaded Object forms the basis of the functionality that allows pthreads to operate. It exposes synchronization methods and some useful interfaces for the programmer. + + + A Thread: + The user can implement a Thread by extending the Thread declaration provided by pthreads implementing the run method. Any members can be written and read by any context with a reference to the Thread, any context can also execute any public and protected methods. The run method of the implementation is executed in a separate thread when the start method of the implementation is called from the context ( that's Thread or Process ) that created it. Only the context that creates a thread can start and join with it. @@ -22,17 +26,12 @@ A Worker Object: A Worker Thread has a persistent state, and will be available from the call to start until the object goes out of scope, or is explicitly shutdown. - Any context with a reference can pass objects of type Stackable to the Worker which will be executed by the Worker in a separate Thread. - The run method of a Worker is executed before any objects on the stack, such that it can initialize resources that the Stackables to come may need. - - - A Stackable Object: - A Stackable Object can read/write and execute the Worker during execution, simply provide the stackable a reference to the appropriate object before runtime. - Additionally, any context with a reference to the Stackable can read, write and execute its methods before during and after execution. + Any context with a reference can stack objects onto the Worker, which will be executed by the Worker in a separate Thread. + The run method of a Worker is executed before any objects on the stack, such that it can initialize resources that the objects to come may need. A Pool: - A Pool of Worker threads can be used to distribute Stackables among programmer declared Worker classes. The Pool class included implements this functionality and takes care of referencing in a sane manner. + A Pool of Worker threads can be used to distribute Threaded objects among Workers. The Pool class included implements this functionality and takes care of referencing in a sane manner. Introduced in v1.0.0, the Pool implementation is the easiest and most efficient way of using multiple threads. @@ -46,13 +45,11 @@ Calling ::wait on an object will cause the context to wait for another context to call ::notify on the same object. This allows for powerful synchronization between Threaded Objects in PHP. + - Wait, Threaded Objects ? - A Stackable, Thread or Worker can be thought of, and should be used as a Threaded stdClass: A Thread, Worker and Stackable all behave in the same way in any context with a reference. - Any objects that are intended for use in the multi-threaded parts of your application should extend the Stackable, Thread or Worker declaration. - Which means they must implement run but may not ever be executed; it will often be the case that Objects being used in a multi-threaded environment are intended for execution. - Doing so means any context ( that's Thread/Worker/Stackable/Process ) with a reference can read, write and execute the members of the Threaded Object before, during, and after execution. - + Any objects that are intended for use in the multi-threaded parts of your application should extend Threaded. + + Method Modifiers: The protected methods of Threaded Objects are protected by pthreads, such that only one context may call that method at a time. @@ -87,12 +84,12 @@ - + &reference.pthreads.setup; &reference.pthreads.constants; + &reference.pthreads.threaded; &reference.pthreads.thread; &reference.pthreads.worker; - &reference.pthreads.stackable; &reference.pthreads.modifiers; &reference.pthreads.pool; &reference.pthreads.mutex; diff --git a/reference/pthreads/cond.xml b/reference/pthreads/cond.xml index 3ca922e1fc..7b076e3b63 100644 --- a/reference/pthreads/cond.xml +++ b/reference/pthreads/cond.xml @@ -3,7 +3,7 @@ - The Cond class + Condition Variable Cond @@ -33,7 +33,7 @@ &Methods; - + diff --git a/reference/pthreads/configure.xml b/reference/pthreads/configure.xml index 5e0fe35fa6..cc23103c31 100644 --- a/reference/pthreads/configure.xml +++ b/reference/pthreads/configure.xml @@ -5,11 +5,19 @@ &reftitle.install; - &pecl.info; - &url.pecl.package;pthreads + Use when compiling PHP. + + Windows users should include php_pthreads.dll into &php.ini; + + + + Windows users also require pthreadVC2.dll in PATH (included with the distribution) + + + diff --git a/reference/pthreads/constants.xml b/reference/pthreads/constants.xml index 0e7777dddc..becbcdff36 100644 --- a/reference/pthreads/constants.xml +++ b/reference/pthreads/constants.xml @@ -1,89 +1,112 @@ + + &reftitle.constants; &extension.constants; - The following constants are for selective inheritance: + + + + PTHREADS_INHERIT_ALL + (integer) + + + + The default options for all Threads, causes pthreads to copy the environment when new Threads are started + + + + + + PTHREADS_INHERIT_NONE + (integer) + + + + Do not inherit anything when new Threads are started + + + + + + PTHREADS_INHERIT_INI + (integer) + + + + Inherit INI entries when new Threads are started + + + + + + PTHREADS_INHERIT_CONSTANTS + (integer) + + + + Inherit user declared constants when new Threads are started + + + + + + PTHREADS_INHERIT_CLASSES + (integer) + + + + Inherit user declared classes when new Threads are started + + + + + + PTHREADS_INHERIT_FUNCTIONS + (integer) + + + + Inherit user declared functions when new Threads are started + + + + + + PTHREADS_INHERIT_INCLUDES + (integer) + + + + Inherit included file information when new Threads are started + + + + + + PTHREADS_INHERIT_COMMENTS + (integer) + + + + Inherit all comments when new Threads are started + + + + + + PTHREADS_ALLOW_HEADERS + (integer) + + + + Allow new Threads to send headers to standard output (normally prohibited) + + + + - - - - PTHREADS_INHERIT_ALL - (integer) - - - - The default inheritance mask used when starting Threads and Workers - - - - - - PTHREADS_INHERIT_INI - (integer) - - - - Determines wether the ini entries are inherited by the new context - - - - - - PTHREADS_INHERIT_CONSTANTS - (integer) - - - - Determines wether the constants are inherited by the new context - - - - - - PTHREADS_INHERIT_CLASSES - (integer) - - - - Determines wether the class table is inherited by the new context - - - - - - PTHREADS_INHERIT_FUNCTIONS - (integer) - - - - Determines wether the function table is inherited by the new context - - - - - - PTHREADS_INHERIT_INCLUDES - (integer) - - - - Determines wether the included_files table is inherit by the new context - - - - - - PTHREADS_INHERIT_NONE - (integer) - - - - Nothing will be inherited by the new context - - - - @@ -33,7 +33,7 @@ &Methods; - + diff --git a/reference/pthreads/pool.xml b/reference/pthreads/pool.xml index a6b2708d78..b08841006d 100644 --- a/reference/pthreads/pool.xml +++ b/reference/pthreads/pool.xml @@ -1,124 +1,123 @@ - - The Pool class - Pool - - - - -
- &reftitle.intro; - - A Pool is a container for, and controller of, a number of Worker threads, the number of threads can be adjusted during execution, additionally the Pool provides an easy mechanism to maintain and collect references in the proper way. - -
- - -
- &reftitle.classsynopsis; - - - - Pool - - - - - Pool - - - - - Properties - - protected - integer - size - - - protected - array - workers - - - protected - array - work - - - protected - integer - last - - - protected - string - class - - - protected - array - ctor - - - &Methods; - - + + + Pooling + Pool + + + + +
+ &reftitle.intro; + + A Pool is a container for, and controller of, an adjustable number of Workers. + + + Pooling provides a higher level abstraction of the Worker functionality, including the management of references in the way required by pthreads. +
+ + +
+ &reftitle.classsynopsis; + + + + Pool + + + + + Pool + + + + &Properties; + + protected + size + + + protected + class + + + protected + workers + + + protected + work + + + protected + ctor + + + protected + last + + + + &Methods; + + + + +
+ +
&reftitle.properties; size - The maximum number of Worker threads allowed in this Pool + maximum number of Workers this Pool can use + + + + class + + the class of the Worker + + + + ctor + + the arguments for constructor of new Workers workers - The array of Worker threads for this Pool + references to Workers work - The array of Stackables submitted to this Pool for execution + references to Threaded objects submitted to the Pool last - The numeric identifier for the last Worker used by this Pool - - - - workers - - The name of the Worker class for this Pool - - - - workers - - The constructor arguments to be passed by this Pool to new Workers upon construction + offset in workers of the last Worker used
- - -
- - &reference.pthreads.entities.pool; - + + + + + + &reference.pthreads.entities.pool; +
- diff --git a/reference/pthreads/setup.xml b/reference/pthreads/setup.xml index 3f7e64bf25..0135e5e700 100644 --- a/reference/pthreads/setup.xml +++ b/reference/pthreads/setup.xml @@ -3,30 +3,31 @@ &reftitle.setup; - +
&reftitle.required; - pthreads requires a build of PHP with ZTS enabled ( --enable-maintainer-zts or --enable-zts on Windows ) + pthreads requires a build of PHP with ZTS enabled ( --enable-maintainer-zts or --enable-zts on Windows )
- - - &reference.pthreads.configure; - - + +
+ &reftitle.install; + &no.install; +
+
&reftitle.runtime; &no.config;
- +
&reftitle.resources; - +
- +
- - - - The Stackable class - Stackable - - - - -
- &reftitle.intro; - - Stackables are tasks that are executed by Worker threads. You can synchronize with, read, and write Stackable objects before, after and during their execution. - -
- - -
- &reftitle.classsynopsis; - - - - Stackable - - - - - Stackable - - - - - &Methods; - - - - -
- -
- - &reference.pthreads.entities.stackable; - -
- - diff --git a/reference/pthreads/thread.xml b/reference/pthreads/thread.xml index f1d02f24b6..b218f2aee8 100644 --- a/reference/pthreads/thread.xml +++ b/reference/pthreads/thread.xml @@ -3,17 +3,25 @@ - The Thread class + Threads Thread - +
&reftitle.intro; - An implementation of a Thread should extend this declaration, implementing the run method. When the start method of that object is called, the run method code will be executed in separate Thread. + When the start method of a Thread is invoked, the run method code will be executed in separate Thread, asynchronously. + + After the run method is executed the Thread will exit immediately, it will be joined with the creating Thread at the approriate time. + + + + Relying on the engine to determine when a Thread should join may cause undesirable behaviour; the programmer should be explicit, where possible. + +
@@ -29,11 +37,32 @@ Thread + + + extends + Threaded + + + + Countable + + + + Traversable + + + + ArrayAccess + &Methods; - + + + &InheritedMethods; + + diff --git a/reference/pthreads/thread/detach.xml b/reference/pthreads/thread/detach.xml new file mode 100644 index 0000000000..edec24dc1c --- /dev/null +++ b/reference/pthreads/thread/detach.xml @@ -0,0 +1,61 @@ + + + + + + Thread::detach + Execution + + + + &reftitle.description; + + public voidThread::detach + + + + Detaches the referenced Thread from the calling context, dangerously! + + + + This method can cause undefined, unsafe behaviour. + It should not usually be used, it is present for completeness and advanced use cases. + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + + + + + + + + diff --git a/reference/pthreads/thread/getcreatorid.xml b/reference/pthreads/thread/getcreatorid.xml index f1e40e4119..2d90ef2200 100644 --- a/reference/pthreads/thread/getcreatorid.xml +++ b/reference/pthreads/thread/getcreatorid.xml @@ -10,7 +10,7 @@ &reftitle.description; - final public longThread::getCreatorId + public integerThread::getCreatorId diff --git a/reference/pthreads/thread/getcurrentthread.xml b/reference/pthreads/thread/getcurrentthread.xml new file mode 100644 index 0000000000..2dcd636a66 --- /dev/null +++ b/reference/pthreads/thread/getcurrentthread.xml @@ -0,0 +1,85 @@ + + + + + + Thread::getCurrentThread + Identification + + + + &reftitle.description; + + public static ThreadThread::getCurrentThread + + + + Return a reference to the currently executing Thread + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + + + + + + &reftitle.examples; + + + Return the currently executing Thread + +start(); +?> +]]> + + &example.outputs; + + + + + + + + + + + diff --git a/reference/pthreads/thread/getcurrentthreadid.xml b/reference/pthreads/thread/getcurrentthreadid.xml index 43e5cd8182..20b611ddfa 100644 --- a/reference/pthreads/thread/getcurrentthreadid.xml +++ b/reference/pthreads/thread/getcurrentthreadid.xml @@ -10,11 +10,11 @@ &reftitle.description; - final public static longThread::getCurrentThreadId + public static integerThread::getCurrentThreadId - Will return the identity of the currently executing thread + Will return the identity of the currently executing Thread diff --git a/reference/pthreads/thread/getthreadid.xml b/reference/pthreads/thread/getthreadid.xml index 4bb18984db..fdfaca53ef 100644 --- a/reference/pthreads/thread/getthreadid.xml +++ b/reference/pthreads/thread/getthreadid.xml @@ -10,7 +10,7 @@ &reftitle.description; - final public longThread::getThreadId + public integerThread::getThreadId diff --git a/reference/pthreads/thread/isjoined.xml b/reference/pthreads/thread/isjoined.xml index 7b9a81710b..b9aa5643a6 100644 --- a/reference/pthreads/thread/isjoined.xml +++ b/reference/pthreads/thread/isjoined.xml @@ -10,11 +10,11 @@ &reftitle.description; - final public booleanThread::isJoined + public booleanThread::isJoined - Tell if the referenced Thread has been joined by another context + Tell if the referenced Thread has been joined @@ -41,7 +41,8 @@ class My extends Thread { public function run() { $this->synchronized(function($thread){ - $thread->wait(); + if (!$thread->done) + $thread->wait(); }, $this); } } @@ -49,6 +50,7 @@ $my = new My(); $my->start(); var_dump($my->isJoined()); $my->synchronized(function($thread){ + $thread->done = true; $thread->notify(); }, $my); ?> diff --git a/reference/pthreads/thread/isstarted.xml b/reference/pthreads/thread/isstarted.xml index 23a8fac862..36ba7ca561 100644 --- a/reference/pthreads/thread/isstarted.xml +++ b/reference/pthreads/thread/isstarted.xml @@ -10,12 +10,13 @@ &reftitle.description; - final public booleanThread::isStarted + public booleanThread::isStarted - Tell if the referenced Thread has been started + Tell if the referenced Thread was started + @@ -26,40 +27,10 @@ &reftitle.returnvalues; - A boolean indication of state + boolean indication of state - - &reftitle.examples; - - - Detect the state of the referenced Thread - -start(); -var_dump($my->isStarted()); -?> -]]> - - &example.outputs; - - - - - - - - + @@ -10,20 +10,66 @@ &reftitle.description; - final public voidThread::kill + public voidThread::kill - Kills the referenced thread, dangerously ! + Forces the referenced Thread to terminate + + + The programmer should not ordinarily kill Threads by force + + + + + + &reftitle.parameters; + &no.function.parameters; &reftitle.returnvalues; - void + A boolean indication of success + + + &reftitle.examples; + + + Kill the referenced Thread + +start(); + +var_dump($t->kill()); +?> +]]> + + &example.outputs; + + + + + + + + \ No newline at end of file +--> diff --git a/reference/pthreads/threaded.xml b/reference/pthreads/threaded.xml new file mode 100644 index 0000000000..d3d78ac827 --- /dev/null +++ b/reference/pthreads/threaded.xml @@ -0,0 +1,82 @@ + + + + + + Thread Safe Objects + Threaded + + + + +
+ &reftitle.intro; + + Threaded objects form the basis of pthreads ability to execute user code asynchronously; they expose and include synchronization methods and various useful interfaces. + + + Threaded objects, most importantly, provide implicit safety for the programmer; all operations on the object scope are safe. + +
+ + +
+ &reftitle.classsynopsis; + + + + Threaded + + + + + Threaded + + + + Traversable + + + + Countable + + + + ArrayAccess + + + + + &Methods; + + + + +
+ +
+ + &reference.pthreads.entities.threaded; + +
+ + diff --git a/reference/pthreads/threaded/chunk.xml b/reference/pthreads/threaded/chunk.xml new file mode 100644 index 0000000000..fb79c77dff --- /dev/null +++ b/reference/pthreads/threaded/chunk.xml @@ -0,0 +1,71 @@ + + + + + + Thread::chunk + Manipulation + + + + &reftitle.description; + + publicarrayThreaded::chunk + integersize + booleanpreserve + + + Fetches a chunk of the objects properties table of the given size, optionally preserving keys + + + + + &reftitle.parameters; + + + size + + + The number of items to fetch + + + + + preserve + + + Preserve the keys of members, by default false + + + + + + + + &reftitle.returnvalues; + + An array of items from the objects property table + + + + + diff --git a/reference/pthreads/threaded/count.xml b/reference/pthreads/threaded/count.xml new file mode 100644 index 0000000000..ee0f383428 --- /dev/null +++ b/reference/pthreads/threaded/count.xml @@ -0,0 +1,56 @@ + + + + + + Threaded::count + Manipulation + + + + &reftitle.description; + + public integerThreaded::count + + + + Returns the number of properties for this object + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + + + + + + + + diff --git a/reference/pthreads/threaded/getterminationinfo.xml b/reference/pthreads/threaded/getterminationinfo.xml new file mode 100644 index 0000000000..31ce4e95f0 --- /dev/null +++ b/reference/pthreads/threaded/getterminationinfo.xml @@ -0,0 +1,56 @@ + + + + + + Threaded::getTerminationInfo + Error Detection + + + + &reftitle.description; + + public arrayThreaded::getTerminationInfo + + + + Retrieves terminal error information from the referenced object + + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + + + + + + + + diff --git a/reference/pthreads/thread/iswaiting.xml b/reference/pthreads/threaded/isrunning.xml similarity index 72% rename from reference/pthreads/thread/iswaiting.xml rename to reference/pthreads/threaded/isrunning.xml index 4f5bd46df7..326e76239a 100644 --- a/reference/pthreads/thread/iswaiting.xml +++ b/reference/pthreads/threaded/isrunning.xml @@ -1,20 +1,20 @@ - + - + - Thread::isWaiting + Thread::isRunning State Detection &reftitle.description; - final public booleanThread::isWaiting + public booleanThreaded::isRunning - Tell if the referenced Thread is waiting for notification + Tell if the referenced object is executing @@ -27,6 +27,11 @@ &reftitle.returnvalues; A boolean indication of state + + + A object is considered running while executing the run method + +
@@ -34,21 +39,23 @@ &reftitle.examples; - Detect the state of the referenced Thread + Detect the state of the referenced object synchronized(function($thread){ - $thread->wait(); + if (!$thread->done) + $thread->wait(); }, $this); } } $my = new My(); $my->start(); +var_dump($my->isRunning()); $my->synchronized(function($thread){ - var_dump($thread->isWaiting()); + $thread->done = true; $thread->notify(); }, $my); ?> diff --git a/reference/pthreads/thread/isterminated.xml b/reference/pthreads/threaded/isterminated.xml similarity index 73% rename from reference/pthreads/thread/isterminated.xml rename to reference/pthreads/threaded/isterminated.xml index cad71125ef..7677f90ce3 100644 --- a/reference/pthreads/thread/isterminated.xml +++ b/reference/pthreads/threaded/isterminated.xml @@ -1,20 +1,20 @@ - + - + - Thread::isTerminated + Threaded::isTerminated State Detection &reftitle.description; - final public booleanThread::isTerminated + public booleanThreaded::isTerminated - Tell if the referenced Thread exited, suffered fatal errors, or threw uncaught exceptions during execution + Tell if the referenced object was terminated during execution; suffered fatal errors, or threw uncaught exceptions @@ -34,7 +34,7 @@ &reftitle.examples; - Detect the state of the referenced Thread + Detect the state of the referenced object \ No newline at end of file +--> diff --git a/reference/pthreads/threaded/iswaiting.xml b/reference/pthreads/threaded/iswaiting.xml new file mode 100644 index 0000000000..af3d05dae3 --- /dev/null +++ b/reference/pthreads/threaded/iswaiting.xml @@ -0,0 +1,92 @@ + + + + + + Threaded::isWaiting + State Detection + + + + &reftitle.description; + + public booleanThreaded::isWaiting + + + + Tell if the referenced object is waiting for notification + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + A boolean indication of state + + + + + &reftitle.examples; + + + Detect the state of the referenced object + +synchronized(function($thread){ + if (!$this->done) + $thread->wait(); + }, $this); + } + + protected $done; +} +$my = new My(); +$my->start(); +$my->synchronized(function($thread){ + var_dump( + $thread->isWaiting()); + $thread->done = true; + $thread->notify(); +}, $my); +?> +]]> + + &example.outputs; + + + + + + + + + diff --git a/reference/pthreads/thread/lock.xml b/reference/pthreads/threaded/lock.xml similarity index 79% rename from reference/pthreads/thread/lock.xml rename to reference/pthreads/threaded/lock.xml index a43b10ee90..0f272375df 100644 --- a/reference/pthreads/thread/lock.xml +++ b/reference/pthreads/threaded/lock.xml @@ -1,20 +1,20 @@ - + - + - Thread::lock + Threaded::lock Synchronization &reftitle.description; - final public booleanThread::lock + public booleanThreaded::lock - Lock the referenced objects storage for the calling context + Lock the referenced objects property table @@ -34,7 +34,7 @@ &reftitle.examples; - Locking Thread Storage + Locking Object Properties + + + + + Threaded::merge + Manipulation + + + + &reftitle.description; + + public booleanThreaded::merge + mixedfrom + mixedoverwrite + + + Merges data into the current object + + + + + &reftitle.parameters; + + + from + + + The data to merge + + + + + overwrite + + + Overwrite existing keys flag, by default true + + + + + + + + &reftitle.returnvalues; + + A boolean indication of success + + + + + diff --git a/reference/pthreads/threaded/notify.xml b/reference/pthreads/threaded/notify.xml new file mode 100644 index 0000000000..c4fd620255 --- /dev/null +++ b/reference/pthreads/threaded/notify.xml @@ -0,0 +1,91 @@ + + + + + + Threaded::notify + Synchronization + + + + &reftitle.description; + + public booleanThreaded::notify + + + + Send notification to the referenced object + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + A boolean indication of success + + + + + &reftitle.examples; + + + Notifications and Waiting + +synchronized(function($thread){ + if (!$thread->done) + $thread->wait(); + }, $this); + } +} +$my = new My(); +$my->start(); +/** send notification to the waiting thread **/ +$my->synchronized(function($thread){ + $thread->done = true; + $thread->notify(); +}, $my); +var_dump($my->join()); +?> +]]> + + &example.outputs; + + + + + + + + + diff --git a/reference/pthreads/threaded/pop.xml b/reference/pthreads/threaded/pop.xml new file mode 100644 index 0000000000..15efca247c --- /dev/null +++ b/reference/pthreads/threaded/pop.xml @@ -0,0 +1,48 @@ + + + + + + Threaded::pop + Manipulation + + + + &reftitle.description; + + public booleanThreaded::pop + + + + Pops an item from the objects property table + + + + + &reftitle.returnvalues; + + The last item from the objects property table + + + + + diff --git a/reference/pthreads/threaded/run.xml b/reference/pthreads/threaded/run.xml new file mode 100644 index 0000000000..b43353d748 --- /dev/null +++ b/reference/pthreads/threaded/run.xml @@ -0,0 +1,55 @@ + + + + + + Threaded::run + Execution + + + + &reftitle.description; + + public voidThreaded::run + + + + The programmer should always implement the run method for objects that are intended for execution. + + + + + &reftitle.parameters; + &no.function.parameters; + + + + &reftitle.returnvalues; + + The methods return value, if used, will be ignored + + + + + + + diff --git a/reference/pthreads/threaded/shift.xml b/reference/pthreads/threaded/shift.xml new file mode 100644 index 0000000000..1979387691 --- /dev/null +++ b/reference/pthreads/threaded/shift.xml @@ -0,0 +1,48 @@ + + + + + + Threaded::shift + Manipulation + + + + &reftitle.description; + + public booleanThreaded::shift + + + + Shifts an item from the objects property table + + + + + &reftitle.returnvalues; + + The first item from the objects property table + + + + + diff --git a/reference/pthreads/threaded/synchronized.xml b/reference/pthreads/threaded/synchronized.xml new file mode 100644 index 0000000000..895d9f8d8e --- /dev/null +++ b/reference/pthreads/threaded/synchronized.xml @@ -0,0 +1,107 @@ + + + + + + Threaded::synchronized + Synchronization + + + + &reftitle.description; + + public mixedThreaded::synchronized + Closureblock + mixed... + + + Executes the block while retaining the referenced objects synchronization lock for the calling context + + + + + &reftitle.parameters; + + + block + + + The block of code to execute + + + + + ... + + + Variable length list of arguments to use as function arguments to the block + + + + + + + + &reftitle.returnvalues; + + The return value from the block + + + + + &reftitle.examples; + + + Synchronizing + +synchronized(function($thread){ + if (!$thread->done) + $thread->wait(); + }, $this); + } +} +$my = new My(); +$my->start(); +$my->synchronized(function($thread){ + $thread->done = true; + $thread->notify(); +}, $my); +var_dump($my->join()); +?> +]]> + + &example.outputs; + + + + + + + + + diff --git a/reference/pthreads/thread/unlock.xml b/reference/pthreads/threaded/unlock.xml similarity index 82% rename from reference/pthreads/thread/unlock.xml rename to reference/pthreads/threaded/unlock.xml index 31e6006571..d18358a44a 100644 --- a/reference/pthreads/thread/unlock.xml +++ b/reference/pthreads/threaded/unlock.xml @@ -1,16 +1,16 @@ - + - + - Thread::unlock + Threaded::unlock Synchronization &reftitle.description; - final public booleanThread::unlock + public booleanThreaded::unlock @@ -34,7 +34,7 @@ &reftitle.examples; - Locking Thread Storage + Locking Object Storage + + + + + Threaded::wait + Synchronization + + + + &reftitle.description; + + public booleanThreaded::wait + integertimeout + + + Will cause the calling context to wait for notification from the referenced object + + + + + &reftitle.parameters; + + + timeout + + + An optional timeout in microseconds + + + + + + + + &reftitle.returnvalues; + + A boolean indication of success + + + + + &reftitle.examples; + + + Notifications and Waiting + +synchronized(function($thread){ + if (!$thread->done) + $thread->wait(); + }, $this); + } +} +$my = new My(); +$my->start(); +/** send notification to the waiting thread **/ +$my->synchronized(function($thread){ + $thread->done = true; + $thread->notify(); +}, $my); +var_dump($my->join()); +?> +]]> + + &example.outputs; + + + + + + + + + diff --git a/reference/pthreads/versions.xml b/reference/pthreads/versions.xml index 53d9239bb4..4bd60c6e3b 100644 --- a/reference/pthreads/versions.xml +++ b/reference/pthreads/versions.xml @@ -5,83 +5,109 @@ --> - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -29,11 +45,32 @@ Worker + + + extends + Thread + + + + Traversable + + + + Countable + + + + ArrayAccess + &Methods; - + + + &InheritedMethods; + + diff --git a/reference/pthreads/worker/getstacked.xml b/reference/pthreads/worker/getstacked.xml index 299fbb84fb..f4b2f0f0fb 100644 --- a/reference/pthreads/worker/getstacked.xml +++ b/reference/pthreads/worker/getstacked.xml @@ -10,11 +10,11 @@ &reftitle.description; - final public intWorker::getStacked + public integerWorker::getStacked - Returns the number of Stackables waiting to be executed by the referenced Worker + Returns the number of objects waiting to be executed by the referenced Worker @@ -26,7 +26,7 @@ &reftitle.returnvalues; - An integral value + An numeric value @@ -38,22 +38,17 @@ stack(new Work()); +$work = new Work(); +$my->stack($work); /** ... **/ printf("My worker has %d jobs remaining\n", $my->getStacked()); /** ... **/ diff --git a/reference/pthreads/worker/isshutdown.xml b/reference/pthreads/worker/isshutdown.xml index 79dc21fa3d..76f9912444 100644 --- a/reference/pthreads/worker/isshutdown.xml +++ b/reference/pthreads/worker/isshutdown.xml @@ -10,7 +10,7 @@ &reftitle.description; - final public booleanWorker::isShutdown + public booleanWorker::isShutdown @@ -39,12 +39,7 @@ start(); var_dump($my->isShutdown()); $my->shutdown(); diff --git a/reference/pthreads/worker/isworking.xml b/reference/pthreads/worker/isworking.xml index 4f378dd692..e6fbd755fc 100644 --- a/reference/pthreads/worker/isworking.xml +++ b/reference/pthreads/worker/isworking.xml @@ -10,7 +10,7 @@ &reftitle.description; - final public booleanWorker::isWorking + public booleanWorker::isWorking @@ -38,12 +38,7 @@ start(); /* ... */ if ($my->isWorking()) { diff --git a/reference/pthreads/worker/shutdown.xml b/reference/pthreads/worker/shutdown.xml index af7831f207..e8ed4a3c6a 100644 --- a/reference/pthreads/worker/shutdown.xml +++ b/reference/pthreads/worker/shutdown.xml @@ -10,11 +10,11 @@ &reftitle.description; - final public booleanWorker::shutdown + public booleanWorker::shutdown - Shuts down the Worker after executing all the Stackables previously stacked + Shuts down the Worker after executing all the objects previously stacked @@ -38,12 +38,7 @@ start(); /* ... */ var_dump($my->shutdown()); diff --git a/reference/pthreads/worker/stack.xml b/reference/pthreads/worker/stack.xml index 3811a8c357..90572fcb38 100644 --- a/reference/pthreads/worker/stack.xml +++ b/reference/pthreads/worker/stack.xml @@ -10,11 +10,11 @@ &reftitle.description; - final public intWorker::stack - Stackablework + public integerWorker::stack + Threadedwork - Appends the referenced Stackable to the stack of the referenced Worker + Appends the referenced object to the stack of the referenced Worker @@ -25,7 +25,7 @@ work - An object of type Stackable to be executed by the referenced Worker + Threaded object to be executed by the referenced Worker @@ -43,11 +43,11 @@ &reftitle.examples; - Passing Stackables to Workers for execution in the Worker Thread + Stacking objects for execution in Workers stack(new Work())); +var_dump($my->stack($work)); /** ... **/ ?> ]]> diff --git a/reference/pthreads/worker/unstack.xml b/reference/pthreads/worker/unstack.xml index ad6b711f1d..f8390f0966 100644 --- a/reference/pthreads/worker/unstack.xml +++ b/reference/pthreads/worker/unstack.xml @@ -10,11 +10,11 @@ &reftitle.description; - final public intWorker::unstack - Stackablework + public integerWorker::unstack + Threadedwork - Removes the referenced Stackable ( or all Stackables if parameters are void ) from stack of the referenced Worker + Removes the referenced object ( or all objects if parameters are void ) from stack of the referenced Worker @@ -25,7 +25,7 @@ work - An object of type Stackable + Threaded object previously stacked onto Worker @@ -43,22 +43,17 @@ &reftitle.examples; - Removing Stackables from Workers + Removing objects from the stack of Workers stack($work)); var_dump($my->unstack($work));