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 ...
随机推荐
-
[转] mysql 存储引擎
最常用的存储引擎 innodb MyISAM MyISAM,这种效率高,不支持事务,不支持外键,每个表有单独的存储文件(多个),方便管理. innodb,一般默认的都是innodb,效率也不低,支持事 ...
-
应用github pages创建自己的个人博客
首先你需要注册自己的github账号 1.登录或者注册github,登录之后点击右上角的“+”号,选择“New repository”菜单,创建仓库,用于存储和博客相关的源文件. 2.跳转页面将填写域 ...
-
Android调用系统自带的文件管理器进行文件选择并读取
先调用: intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType("*/*"); //设置类型,我这里是任意类 ...
-
Java集合和PHP的对比
这里突然感觉到在java中的集合,和php的数组非常相似 .
-
JavaScript之ClassName属性学习
在前面的style属性学习中,知道了通过style属性可以控制元素的样式,从而实现了行为层通过DOM的style属性去干预变现层显示的目地,但是这种就是不好的,而且为了实现通过DOM脚本设置的样式,你 ...
-
附加被分离DB
如何附加被分离的质疑数据库? 简介 有些时间,由于日志损坏等原因,导致了数据库质疑.如果此时你分离了数据库,那你会发现你无法再附加上数据库,那后果还是很严重的.因此本文提供了一种方式,可以使得当数 ...
-
Gradle 1.12用户指南翻译——第二十八章. Jetty 插件
其他章节的翻译请参见: http://blog.csdn.net/column/details/gradle-translation.html 翻译项目请关注Github上的地址: https://g ...
-
HDU 6315 Naive Operations(线段树区间整除区间)
Problem DescriptionIn a galaxy far, far away, there are two integer sequence a and b of length n.b i ...
-
hdu 5084 前缀和预处理
http://acm.hdu.edu.cn/showproblem.php?pid=5084 给出矩阵M,求M*M矩阵的r行c列的数,每个查询跟前一个查询的结果有关. 观察该矩阵得知,令ans = M ...
-
Jon Snow and his Favourite Number CodeForces - 768C (技巧)
链接 题意 给定数组, 每次操作先将数组排序, 再将奇数位全部异或x, 求k次操作后数组最大值与最小值 (1 ≤ n ≤ 105, 0 ≤ k ≤ 105, 0 ≤ x ≤ 103) 题解 直接暴力模 ...