Pool
class Pool (View source)
(PECL pthreads >= 2.0.0)
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.
Properties
protected int | $size | Maximum number of Workers this Pool can use |
|
protected string | $class | The class of the Worker |
|
protected array | $ctor | The arguments for constructor of new Workers |
|
protected array | $workers | References to Workers |
|
protected int | $last | Offset in workers of the last Worker used |
Methods
(PECL pthreads >= 2.0.0)
Construct a new pool of workers. Pools lazily create their threads, which means
new threads will only be spawned when they are required to execute tasks.
(PECL pthreads >= 2.0.0)
Allows the pool to collect references determined to be garbage by the
optionally given collector
(PECL pthreads >= 2.0.0)
Resize the Pool
(PECL pthreads >= 2.0.0)
Shuts down all of the workers in the pool. This will block until all submitted
tasks have been executed.
Details
__construct(int $size, string $class = 'Worker', array $ctor = [])
(PECL pthreads >= 2.0.0)
Construct a new pool of workers. Pools lazily create their threads, which means
new threads will only be spawned when they are required to execute tasks.
int
collect(callable|null $collector = null)
(PECL pthreads >= 2.0.0)
Allows the pool to collect references determined to be garbage by the
optionally given collector
void
resize(int $size)
(PECL pthreads >= 2.0.0)
Resize the Pool
void
shutdown()
(PECL pthreads >= 2.0.0)
Shuts down all of the workers in the pool. This will block until all submitted
tasks have been executed.
int
submit(Threaded $task)
(PECL pthreads >= 2.0.0)
Submit the task to the next Worker in the Pool
int
submitTo(int $worker, Threaded $task)
(PECL pthreads >= 2.0.0)
Submit a task to the specified worker in the pool. The workers are indexed
from 0, and will only exist if the pool has needed to create them (since
threads are lazily spawned).