pthreads 2.0.10 test
来源:互联网 发布:取消淘宝账号实名认证 编辑:程序博客网 时间:2024/05/18 21:10
CentOS 6.3
cd /root
mkdir pthreads
//get php-5.6 and install zts version
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
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,则是同时多线程执行的。
0 0
- pthreads 2.0.10 test
- Pthreads
- pthreads
- pthreads
- pthreads 链接
- man pthreads
- Pthreads笔记
- pthreads手册
- pthreads API
- Pthreads-win32
- Pthreads必知必会
- Pthreads mutex vs Pthreads spinlock
- Pthreads mutex vs Pthreads spinlock
- Pthreads mutex VS Pthreads spinlock
- Pthreads mutex vs Pthreads spinlock
- Pthreads mutex vs Pthreads spinlock
- Pthreads mutex VS Pthreads spinlock
- Pthreads mutex VS Pthreads spinlock
- iOS TextField输入框点击键盘时随着键盘上移
- HDU 2545 树上战争
- Windows系统Eclipse的copy lines默认快捷键Ctrl+alt+down不可用
- Android入门(54)——第九章 使用GestureOverlayView进行手势识别
- nginx日志文件切割
- pthreads 2.0.10 test
- 原型模式的浅度克隆和深度克隆的实现
- 基于jquery的秒表倒计时
- tarjan题目(1)Victoria的舞会2
- 基于windbg的内存泄露分析
- 在Hibernate Validator 4.1+中,@NotNull, @NotEmpty和@NotBlank之间的区别是什么?
- 单片机内部扩展RAM
- Find Minimum in Rotated Sorted Array II
- 跳转webview白屏(黑屏)问题解决