PHPCon Poland 2024

La classe Threaded

(PECL pthreads >= 2.0.0)


Les objets Threaded sont la base de pthreads pour exécuter du code de facon parallèle; ils exposent et incluent des méthodes de synchronisation ainsi que diverses interfaces utiles.

Les objets Threaded fournissent une sécurité native pour le développeur; toutes les opérations sont thread-safe dans le scope de l'objet.

Synopsis de la classe

class Threaded implements Collectable, Traversable, Countable, ArrayAccess {
/* Méthodes */
public chunk(int $size, bool $preserve): array
public count(): int
public extend(string $class): bool
public isRunning(): bool
public isTerminated(): bool
public merge(mixed $from, bool $overwrite = ?): bool
public notify(): bool
public notifyOne(): bool
public pop(): bool
public run(): void
public shift(): bool
public synchronized(Closure $block, mixed ...$args): mixed
public wait(int $timeout = ?): bool


add a note

User Contributed Notes 2 notes

derkontrollfreak+php at gmail dot com
8 years ago
> Threaded objects, most importantly, provide implicit safety for the programmer; all operations on the object scope are safe.

However, this comes with a trade-off: Operations on the instance scope are slower than on plain PHP objects.

Static properties are not affected as they are thread-local.
jtbibliomania at gmail dot com
4 years ago
It's worth mentioning here that, since v2.0.0, 'Stackable' class was an alias for 'Threaded' class but has been removed since.
To Top