pthreadsInhaltsverzeichnis
The Threaded classEinführungThreaded objects form the basis of pthreads ability to execute user code in parallel; they expose synchronization methods and various useful interfaces. Threaded objects, most importantly, provide implicit safety for the programmer; all operations on the object scope are safe. KlassenbeschreibungThreaded
class Threaded
implements
Traversable
,
Countable
,
ArrayAccess
{
/* Methoden */
public array chunk
( integer
$size
, boolean $preserve
)
public integer count
( void
)
public bool extend
( string
$class
)
public Threaded from
( Closure
$run
[, Closure $construct
[, array $args
]] )
public array getTerminationInfo
( void
)
public boolean isRunning
( void
)
public boolean isTerminated
( void
)
public boolean isWaiting
( void
)
public boolean lock
( void
)
public boolean merge
( mixed
$from
[, bool $overwrite
] )
public boolean notify
( void
)
public boolean pop
( void
)
public void run
( void
)
public mixed shift
( void
)
public mixed synchronized
( Closure
$block
[, mixed $...
] )
public boolean unlock
( void
)
public boolean wait
([ integer
}$timeout
] )The Thread classEinführungWhen the start method of a Thread is invoked, the run method code will be executed in separate Thread, in parallel. After the run method is executed the Thread will exit immediately, it will be joined with the creating Thread at the appropriate time. Warnung
Relying on the engine to determine when a Thread should join may cause undesirable behaviour; the programmer should be explicit, where possible. KlassenbeschreibungThread
class Thread
extends
Threaded
implements
Countable
,
Traversable
,
ArrayAccess
{
/* Methoden */
public void detach
( void
)
public integer getCreatorId
( void
)
public static Thread getCurrentThread
( void
)
public static integer getCurrentThreadId
( void
)
public integer getThreadId
( void
)
public static mixed globally
( void
)
public boolean isJoined
( void
)
public boolean isStarted
( void
)
public boolean join
( void
)
public void kill
( void
)
public boolean start
([ integer
$options
] )/* Geerbte Methoden */
public array Threaded::chunk
( integer
$size
, boolean $preserve
)
public integer Threaded::count
( void
)
public bool Threaded::extend
( string
$class
)
public Threaded Threaded::from
( Closure
$run
[, Closure $construct
[, array $args
]] )
public array Threaded::getTerminationInfo
( void
)
public boolean Threaded::isRunning
( void
)
public boolean Threaded::isTerminated
( void
)
public boolean Threaded::isWaiting
( void
)
public boolean Threaded::lock
( void
)
public boolean Threaded::merge
( mixed
$from
[, bool $overwrite
] )
public boolean Threaded::notify
( void
)
public boolean Threaded::pop
( void
)
public void Threaded::run
( void
)
public mixed Threaded::shift
( void
)
public mixed Threaded::synchronized
( Closure
$block
[, mixed $...
] )
public boolean Threaded::unlock
( void
)
public boolean Threaded::wait
([ integer
}$timeout
] )The Worker classEinführungWorker Threads have a persistent context, as such should be used over Threads in most cases. When a Worker is started, the run method will be executed, but the Thread will not leave until one of the following conditions are met:
This means the programmer can reuse the context throughout execution; placing objects on the stack of the Worker will cause the Worker to execute the stacked objects run method. Warnung
The programmer must retain references to stacked objects until they are executed or unstacked; the Pool class provides a higher level abstraction of the Worker functionality and manages references for the programmer. KlassenbeschreibungWorker
class Worker
extends
Thread
implements
Traversable
,
Countable
,
ArrayAccess
{
/* Methoden */
public int collect
([ Callable
$collector
] )
public int getStacked
( void
)
public bool isShutdown
( void
)
public boolean isWorking
( void
)
public bool shutdown
( void
)
public int stack
( Threaded
&$work
)
public int unstack
( void
)
/* Geerbte Methoden */
public void Thread::detach
( void
)
public integer Thread::getCreatorId
( void
)
public static Thread Thread::getCurrentThread
( void
)
public static integer Thread::getCurrentThreadId
( void
)
public integer Thread::getThreadId
( void
)
public static mixed Thread::globally
( void
)
public boolean Thread::isJoined
( void
)
public boolean Thread::isStarted
( void
)
public boolean Thread::join
( void
)
public void Thread::kill
( void
)
public boolean Thread::start
([ integer
}$options
] )The Collectable interfaceEinführungAchtung
Collectable was previously a class (in pthreads v2 and below). Now, it is an interface in pthreads v3 that is implemented by the Threaded class. Represents a garbage-collectable object. Interface-ÜbersichtCollectable
class Collectable
extends
Threaded
{
/* Methoden */
public bool isGarbage
( void
)
public void setGarbage
( void
)
}The Pool classEinführungA 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. KlassenbeschreibungPool
class Pool
{
/* Eigenschaften */
protected
$size
;
protected
$class
;
protected
$workers
;
protected
$work
;
protected
$ctor
;
protected
$last
;
/* Methoden */
public int collect
([ Callable
$collector
] )
public Pool __construct
( integer
$size
[, string $class
[, array $ctor
]] )
public void resize
( integer
$size
)
public void shutdown
( void
)
public int submit
( Threaded
$task
)
public int submitTo
( int
}$worker
, Threaded $task
)Eigenschaften
The Mutex classEinführungWarnung
The Mutex class has been removed in pthreads v3. The static methods contained in the Mutex class provide direct access to Posix Mutex functionality. KlassenbeschreibungMutex
class Mutex
{
/* Methoden */
final
public
static
long
create
([
boolean
$lock
] )
final
public
static
boolean
destroy
(
long
$mutex
)
final
public
static
boolean
lock
(
long
$mutex
)
final
public
static
boolean
trylock
(
long
$mutex
)
final
public
static
boolean
unlock
(
long
}$mutex
[,
boolean
$destroy
] )The Cond classEinführungWarnung
The Cond class has been removed in pthreads v3. The static methods contained in the Cond class provide direct access to Posix Condition Variables. KlassenbeschreibungCond
class Cond
{
/* Methoden */
final
public
static
boolean
broadcast
(
long
$condition
)
final
public
static
long
create
( void
)
final
public
static
boolean
destroy
(
long
$condition
)
final
public
static
boolean
signal
(
long
$condition
)
final
public
static
boolean
wait
(
long
}$condition
,
long
$mutex
[,
long
$timeout
] ) |