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 ...
随机推荐
- FPGA重要设计思想
FPGA重要设计思想 1.速度和面积互换原则.以面积换速度可以实现很高的数据吞吐率,其实串/并转换.就是一种以面积换速度的思想 2.乒乓操作. 3.串/并转换的思想. 高速数据处理的重要技巧之一. ...
- 读《编写可维护的JavaScript》第11章总结
这周也是拿到了同程的offer,从此走上了前端之路!感谢我的贵人们.再次纪念一下~! 第11章 不是你的对象不要动 11.1 什么是你的 你的对象:当你的代码创建了这些对象或者你有职责维护其他人的代码 ...
- 数据源增量处理(Delta Proess)三大属性:Recod Mode、Delta Type、Serialization
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- ASP.NET MVC bootstrap 3 ie 8兼容问题及错误解决(取消IE禁用IE脚本调试定位js文件错误)
因要做一个B/S架构的项目,使用MVC框架技术,本人不擅长页面设计美工,只好用bootstrap框架,在chrome内核系列的浏览器和IE 11中显示都没有问题,但是在 IE 8下显示却不正常,表格无 ...
- Linux-设置固定IP
第一步:激活网卡 系统装好后默认的网卡是eth0,用下面的命令将这块网卡激活. # ifconfig eth0 up 第二步:设置网卡进入系统时启动 想要每次开机就可以自动获取IP地址上网,就要设置网 ...
- Python 安装Twisted 提示python version 2.7 required,which was not found in the registry
由于我安装Python64位的,下载后没注册,安装Twisted时老提示“python version 2.7 required,which was not found in the registry ...
- 一个简单确非常实用的javascript函数
在写js的时候,往往会碰到字符串拼接的问题,如果简单,直接使用+号连接字符串就可以了, 但是如果复杂,+用起来就非常不爽,在.net中有,Sting.Format函数,用起来还是很爽的,于是就想着js ...
- linux应用程序开发-进程程序设计
学习之前必须了解基本的概念: 进程,线程,进程3种状态,进程调度以及4种算法,进程同步,死锁,记不清的找度娘. 获取ID #include<sys/types.h> #include< ...
- VERY DEEP CONVOLUTIONAL NETWORKS FOR LARGE-SCALE IMAGE RECOGNITION 这篇论文
由Andrew Zisserman 教授主导的 VGG 的 ILSVRC 的大赛中的卷积神经网络取得了很好的成绩,这篇文章详细说明了网络相关事宜. 文章主要干了点什么事呢?它就是在在用卷积神经网络下, ...
- hibernate一级缓存的源码初窥
hibernate的一级缓存的存在使得hibernate可以在操作实体化对象的时候减少对于数据库的访问.hibernate的一级缓存实际上就是指的session缓存,它的生命周期和session相同. ...