PHP 8.1.24 Released!

La clase Thread

(PECL pthreads >= 2.0.0)

Introducción

Cuando se invoca al método start de Thread, se ejecutará el código del método run en un Thread diferente, en paralelo.

Después de ejecutar el método run, el Thread terminará inmediatamente; será unido al Thread creador en el momento apropiado.

Advertencia

Depender del motor para determinar cuándo un Thread debería unirse podría ocasionar un comportamiento no deseado; el programador debería ser explícito siempre que sea posible.

Sinopsis de la Clase

class Thread extends Threaded implements Countable, Traversable, ArrayAccess {
/* Métodos */
public getCreatorId(): integer
public static getCurrentThread(): Thread
public static getCurrentThreadId(): int
public getThreadId(): int
public isJoined(): bool
public isStarted(): bool
public join(): bool
public start(int $options = ?): bool
/* Métodos heredados */
public Threaded::chunk(int $size, bool $preserve): array
public Threaded::count(): int
public Threaded::extend(string $class): bool
public Threaded::isRunning(): bool
public Threaded::isTerminated(): bool
public Threaded::merge(mixed $from, bool $overwrite = ?): bool
public Threaded::notify(): bool
public Threaded::notifyOne(): bool
public Threaded::pop(): bool
public Threaded::run(): void
public Threaded::synchronized(Closure $block, mixed ...$args): mixed
public Threaded::wait(int $timeout = ?): bool
}

Tabla de contenidos

add a note

User Contributed Notes 2 notes

up
9
german dot bernhardt at gmail dot com
9 years ago
<?php

class workerThread extends Thread {
public function
__construct($i){
$this->i=$i;
}

public function
run(){
while(
true){
echo
$this->i;
sleep(1);
}
}
}

for(
$i=0;$i<50;$i++){
$workers[$i]=new workerThread($i);
$workers[$i]->start();
}

?>
up
4
german dot bernhardt at gmail dot com
7 years ago
<?php
# ERROR GLOBAL VARIABLES IMPORT

$tester=true;

function
tester(){
global
$tester;
var_dump($tester);
}

tester(); // PRINT -> bool(true)

class test extends Thread{
public function
run(){
global
$tester;
tester(); // PRINT -> NULL
}
}
$workers=new test();
$workers->start();

?>
To Top