La clase Thread

(PECL pthreads >= 2.0.0)

Introducción

Cuando el método start de un Thread es llamado, el código del método run será ejecutado de forma paralela en un Thread separado.

Después de la ejecución del método run, el Thread se terminará inmediatamente, será vinculado al Thread original posteriormente.

Advertencia

Basarse en el motor para determinar cuándo un Thread será vinculado puede provocar un comportamiento no deseado. El desarrollador debe ser explícito en la medida de lo posible.

Sinopsis de la Clase

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

Tabla de contenidos

add a note

User Contributed Notes 2 notes

up
16
german dot bernhardt at gmail dot com
12 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
10 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