pthreads 2.0.10 test
CentOS 6.3
cd /root
mkdir pthreads
//get php-5.6 and install zts version
wget cn2.php.net/get/php-5.6.11.tar.gz/from/this/mirror
tar zxf /php-5.6.11.tar.gz
cd /php-5.6.11
./configure --prefix=/usr/local/php-zts --with-config-file-path=/usr/local/php-zts/etc --enable-fpm --with-fpm-user=apache --with-fpm-group=apache --enable-mbstring --enable-xml --with-mysql --with-mysqli --with-iconv-dir --enable-maintainer-zts --enable-zip
--enable-pcntl --enable-sockets
make
make install
//get pthreads
wget http://pecl.php.net/get/pthreads
tar zxf pthreads-2.0.10.tgz
cd pthreads-2.0.10
./configure --with-php-config=/usr/local/php-zts/bin/php-confi
make
make install
vi /usr/local/php-zts/etc/php.ini
add:
extension=pthreads.so
cd examples
/usr/local/php-zts/bin/php Mutexes.php
<?php
/* this seems like a pretty good way to show you the difference between threads that are syncrhonized with mutex and those that aren't */
/* will show 50 very neat rows <-.........-> then 50 threads doing the same thing with no mutex */
class MyWorkerThread extends Thread {
public function __construct($limit, $mutex, $id){
$this->limit = $limit;
$this->mutex = $mutex;
$this->id = $id;
} public function run(){
if($this->mutex)
$locked=Mutex::lock($this->mutex);
printf("%s#%lu:<-", !empty($locked)?"Y":"N", $this->id);
$i=0;
sleep(rand(1,3));
while($i++<$this->limit){
echo ".";
}
printf("->\n");
if($this->mutex)
Mutex::unlock($this->mutex);
return true;
}
} $timer = microtime(true);
/* create and lock a mutex */
$mutex = Mutex::create(true);
/* create workers */
$workers = array();
for($i=0;$i<10;$i++){
$workers[$i]=new MyWorkerThread(rand(30, 100), $mutex,$i);
/* they cannot go anywhere, I have the mutex */
$workers[$i]->start();
}
printf("Release the (muzzled) hounds ... :\n");
Mutex::unlock($mutex);
foreach($workers as $i=> $worker)
$workers[$i]->join();
printf("Muzzled: %f seconds\n", microtime(true)-$timer);
/* please remember to destroy mutex and condition variables */
Mutex::destroy($mutex); $timer = microtime(true);
/* same again, no mutex */
printf("Now no mutex ... :\n");
$workers = array();
for($i=0;$i<10;$i++){
$workers[$i]=new MyWorkerThread(rand(30, 100),null,$i);
/* they cannot go anywhere, I have the mutex */
$workers[$i]->start();
}
foreach($workers as $worker)
$worker->join();
printf("Dribbling: %f seconds\n", microtime(true)-$timer);
?>
改了一下,可以明显看到用了Mute会是按照顺序执行,而不用Mute,则是同时多线程执行的。
pthreads 2.0.10 test的更多相关文章
- CentOS7 编译安装 Nodejs (实测 笔记 Centos 7.0 + node 0.10.33)
环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.准备 1.1 显示系统版 ...
- Time.deltaTime 的平均值在0.1-0.2左右
Time.deltaTime 平均值在0.1-0.2左右 低的在0.03 高的在0.3
- kafka0.9.0及0.10.0配置属性
问题导读1.borker包含哪些属性?2.Producer包含哪些属性?3.Consumer如何配置?borker(0.9.0及0.10.0)配置Kafka日志本身是由多个日志段组成(log segm ...
- how to build apache log4cxx 0.10 by Visual Studio 201*
Chapter 1 Official Steps We are going to follow the steps here, http://logging.apache.org/log4cxx/b ...
- Microsoft.Bcl.Build 1.0.10 稳定版发布
Microsoft.Bcl.Build 1.0.10 稳定版发布 解决了之前 1.0.8 在未下载相应的Nuget Package 的情况下项目无法加载的情况 但由于 Microsoft.Net.Ht ...
- 小红伞和virtualbox5.0.10冲突
win7 sp1 64bit 旗舰版:virtual box 5.0.10 提示 error in supr3hardNtChildWaitFor……Timed out after 60001 ms ...
- Kafka 0.10.0
2.1 Producer API We encourage all new development to use the new Java producer. This client is produ ...
- DotNetBar v12.7.0.10 Fully Cracked
更新信息: http://www.devcomponents.com/customeronly/releasenotes.asp?p=dnbwf&v=12.7.0.10 如果遇到破解问题可以与 ...
- (原创)win7自带IIS7.5+php7.0.10安装教程(图)
php在上周8月18日发布了PHP 7.0 (7.0.10)版本.详细下载页面http://windows.php.net/download/,根据自身电脑配置情况酌情下载版本.win7旗舰版,iis ...
随机推荐
- JQuery下focus()无法自动获取焦点的处理方法 jquery如何使文本框获得焦点
今天遇见这么一个小小的问题,就是文本框中需要输入内容才可以提交,如果没有输入就提示并使该文本框获得焦点! 这么一个简单的事情如果没有使用 jQuery的话 是不是对象.focus()就可以了, Jav ...
- 使用xfire工具搭建webservice
一个简单的项目,下载下来导入可以直接使用 https://yunpan.cn/cY8ANUAYLgy7s 访问密码 99e3
- Cheatsheet: 2016 05.01 ~ 05.31
Other Awesome Go - A curated list of awesome Go frameworks, libraries and software Visual Studio Cod ...
- sql连表分页查询(存储过程)
1.平时分页查询都比较多针对一个表的数据 而这个分页查询是针对连表查询的 ,这也是我网上改版别人的sql语句 先在数据库新建一个存储过程 拷贝以下代码 CREATE PROCEDURE [dbo].[ ...
- 调用微信JsAPI端获取位置
public partial class test : BasePage { protected test() { AccessPage = PageWebType.WX; } protected s ...
- WebUpLoder 能自动预览,能多实例,包括后台demo
样式在网上找的.样子: 懒得写别的了,代码里面我写的注释挺详细的:https://github.com/zhangsai521314/WebUpLoder 写文不易,转载请注明出处:http://ww ...
- JAVA 1.4 算术运算
1. 如果在一个算术运算中有int,double,float那么最终运算的结果是double,那么也就是说参与运算的类型和得到的结果:结果一定是参与运算的精度最高的那个类型 2. 算术运算中的除法 i ...
- sql server 查询表结构
--查询表结构start SELECT 序号 = a.colorder,字段名称 = a.name,字段描述 = f.value, 标识 then '√' else '' end, 主键 FROM s ...
- python 03
数据结构 在 python 中有4种内建数据结构, 列表, 元组, 字典和集合. 列表 list 有序项目的数据结构, 类似数组, 是对象. 列表用中括号中用逗号分隔的项目定义.例如 ['apple' ...
- 转!!java事务的处理
java的事务处理,如果对数据库进行多次操作,每一次的执行或步骤都是一个事务.如果数据库操作在某一步没有执行或出现异常而导致事务失败,这样有的事务被执行有的就没有被执行,从而就有了事务的回滚,取消先前 ...