
![[تصویر: 0tvn_untitled.png]](http://uupload.ir/files/0tvn_untitled.png)
کد PHP:
<?phpclass MyClassName extends Thread
{
private $classId = NULL; function
__construct()
{
$this->classId = rand(1, 9);
retu;
} function
run()
{
for ($i = 1 ; $i < 10; $i ++)
{
echo ("Object: #{$this->classId} - current executing thread UID: " . $this->getCurrentThreadId() . PHP_EOL);
sleep(25);
retu;
}
}
}const
THREADS = 4;for (
$i = 0; $i < THREADS; $i ++)
{
$pool[] = new MyClassName();
}foreach (
$pool as $worker)
{
if (!$worker->isStarted())
{
if (!$worker->start())
{
echo 'Error starting thread.';
break;
}
}
else
{
echo 'The thread is already started.';
break;
}
}foreach (
$pool as $worker)
{
if ($worker->isStarted())
{
if (!$worker->isJoined())
{
if (!$worker->join())
{
echo 'Error joining thread.';
break;
}
}
else
{
echo 'The thread is already joined.';
break;
}
}
else
{
echo 'The thread is not started.';
break;
}
}?>کد:
Object: #5 - current executing thread UID: 1844
Object: #4 - current executing thread UID: 2760
Object: #8 - current executing thread UID: 2928
Object: #4 - current executing thread UID: 1592
دکتر مصطفی چمران: می گویند تقوا از تخصص لازمتر است، آنرا می پذیرم، اما می گویم: آنکس که تخصص ندارد و کاری را می پذیرد، بی تقواست.
php مرکز کد های سایت...ما را در سایت php مرکز کد های سایت دنبال میکنید
برچسب: pthread threading,pthread threading model,c, threading pthread create,c, threading pthread, نویسنده: استخدام کار بازدید: 234