文字

pthreads

  • 简介
  • 安装/配置
    • 需求
    • 安装
    • 运行时配置
  • 预定义常量
  • Threaded — Threaded 类
    • Threaded::chunk — 操作
    • Threaded::count — Manipulation
    • Threaded::extend — Runtime Manipulation
    • Threaded::from — Creation
    • Threaded::getTerminationInfo — Error Detection
    • Threaded::isRunning — State Detection
    • Threaded::isTerminated — State Detection
    • Threaded::isWaiting — State Detection
    • Threaded::lock — Synchronization
    • Threaded::merge — Manipulation
    • Threaded::notify — Synchronization
    • Threaded::pop — Manipulation
    • Threaded::run — Execution
    • Threaded::shift — Manipulation
    • Threaded::synchronized — Synchronization
    • Threaded::unlock — Synchronization
    • Threaded::wait — Synchronization
  • Thread — Thread 类
    • Thread::detach — 执行
    • Thread::getCreatorId — 识别
    • Thread::getCurrentThread — 识别
    • Thread::getCurrentThreadId — 识别
    • Thread::getThreadId — 识别
    • Thread::globally — 执行
    • Thread::isJoined — 状态监测
    • Thread::isStarted — 状态检测
    • Thread::join — 同步
    • Thread::kill — 执行
    • Thread::start — 执行
  • Worker — Worker 类
    • Worker::getStacked — 栈分析
    • Worker::isShutdown — 状态检测
    • Worker::isWorking — 状态检测
    • Worker::shutdown — 同步
    • Worker::stack — 栈操作
    • Worker::unstack — 栈操作
  • Collectable — The Collectable class
    • Collectable::isGarbage — Determine whether an object has been marked as garbage
    • Collectable::setGarbage — Mark an object as garbage
  • Modifiers — 方法修饰符
  • Pool — Pool 类
    • Pool::collect — 回收已完成任务的引用
    • Pool::__construct — 创建新的 Worker 对象池
    • Pool::resize — 改变 Pool 对象的可容纳 Worker 对象的数量
    • Pool::shutdown — 停止所有的 Worker 对象
    • Pool::submit — 提交对象以执行
    • Pool::submitTo — 提交对象以执行
  • Mutex — Mutex 类
    • Mutex::create — 创建一个互斥量
    • Mutex::destroy — 销毁互斥量
    • Mutex::lock — 给互斥量加锁
    • Mutex::trylock — 尝试给互斥量加锁
    • Mutex::unlock — 释放互斥量上的锁
  • Cond — Cond 类
    • Cond::broadcast — 广播条件变量
    • Cond::create — 创建一个条件变量
    • Cond::destroy — 销毁条件变量
    • Cond::signal — 发送唤醒信号
    • Cond::wait — 等待

用户评论:

[#1] r3x at engelhardt-stefan dot de [2015-11-17 06:17:20]

If you try to test threading, remember to let php think slow:

Skript: -- C:\Webserver\htdocs>php mttest.php

<?php
class My extends Thread{
    function 
run(){
        for(
$i=1;$i<10;$i++){
            echo 
Thread::getCurrentThreadId() .  "\n";
            
sleep(2);     // <------
        
}
    }
}

for(
$i=0;$i<2;$i++){
    
$pool[] = new My(); 
}

foreach(
$pool as $worker){
    
$worker->start();
}
foreach(
$pool as $worker){
    
$worker->join();
}
?>


Output: -- C:\Webserver\htdocs>php mttest.php
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816
6300
5816

If you leave sleep() out, the cpu-time for the threads is long enough to complete the script at once.

[#2] 312036773 at qq dot com [2015-11-06 04:52:21]

My code is :

<?php
class My extends Thread{
    function 
run(){
        for(
$i=1;$i<10;$i++){
            echo 
Thread::getCurrentThreadId() .  "<br/>";
            
        }
    }
}

for(
$i=0;$i<2;$i++){
    
$pool[] = new My();    
}

foreach(
$pool as $worker){
    
$worker->start();
    
$worker->join();
}
?>


The result is :
4076
4076
4076
4076
4076
4076
4076
4076
4076
5760
5760
5760
5760
5760
5760
5760
5760
5760

How can I make it run  like below??? Thread switch?

4076
5760
4076
5760
4076
5760
4076
5760
4076
5760
5760

[#3] admin at deosnet dot com [2014-08-19 10:01:15]

Hello,

WARNING : When using Stackable objects in callable functions by your Threads, you must be very careful if you use it as an array. Indeed, if you do not copy your Stackable "array" in a local variable, the execution time can drop drastically !

Also, if you want to modify an array() in a function, you will also store in a local variable in order that your array is in a thread-safe context.

[#4] jasonrlester at yahoo dot com [2014-02-23 00:08:57]

Note that this extension *is* a high level implementation of POSIX threads, including on Windows (which is why pthreadsV*.dll is required)

[#5] Anonymous [2014-02-08 11:04:44]

This seriously should be renamed. People will interpret this as the widely known POSIX threads, which it's not. Just a heads up for anyone wanting to use "pthreads".

上一篇: 下一篇: