test pthread code
#include <iostream>
#include <pthread.h>
using namespace std;
int sum=;
void * add(void *);
pthread_mutex_t mut;
int main()
{
pthread_t thread[];
int num;
long count;
cout<<"Enter the number of thread (1-10):";
cin>>num;
cout<<"Enther the number to count to:";
cin>>count ;
for (int x=;x<num;x++)
{
pthread_create(&thread[x],NULL,add, (void*) count); } for (int x=;x<num;x++)
pthread_join(thread[x],NULL); //ensure every thread terminated cout<<sum<<endl;
return ; } void *add(void *count)
{
long num;
num=(long) count;
// pthread_mutex_lock(&mut);
for (long x=;x<=num;x++)
{
sum+=x;
//cout<<sum<<'\t'<<x<<endl;
}
//pthread_mutex_unlock(&mut);
}
test pthread code的更多相关文章
- NPTL vs PThread
NPTL vs PThread POSIX threads (pthread) is not an implementation, it is a API specification (a stand ...
- Linux Pthread 深入解析(转-度娘818)
Linux Pthread 深入解析 Outline - 1.线程特点 - 2.pthread创建 - 3.pthread终止 - 4.mutex互斥量使用框架 - ...
- 创建线程方式-pthread
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- Linux 下子线程 exit code 在主线程中的使用
Linux线程函数原型是这样的: void* thread_fun(void* arg) 它的返回值是 空类型指针,入口参数也是 空类型指针.那么线程的 exit code 也应该是 void * 类 ...
- pthread clean up
https://www.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part4/ http://www.cnblogs.com/xfi ...
- 【转】用Pthread创建线程的一个简单Demo
一.我们直接在COCOS2D-X自带的HelloWorld工程中添加代码.首先将Pthread的文件包含进来包括lib文件.在HelloWorld.cpp中引入头文件和库. #include &quo ...
- pthread小结
参考1 https://computing.llnl.gov/tutorials/pthreads/ 参考2 http://man7.org/linux/man-pages/man7/pthreads ...
- pthread 线程立即取消的两种方法
1.相关函数介绍 a. int pthread_cancel(pthread_t thread) 1发送终止信号给thread线程,如果成功则返回0,否则为非0值.发送成功并不意味着thread会终止 ...
- NDK中使用pthread多线程中自己写的一个BUG
在使用pthread进行NDK中的多线程开发时,自己写了一个BUG, void *darkGrayThread(void *args) { ThreadParam *param = (ThreadPa ...
随机推荐
- 建立请求号 request
1:获取TR号(一般由团队的负责人创建,发出) 2:进入 i7p系统 3:点击process 4:输入tr号 5:选中 正确的请求号,右键> process item> add task ...
- Mac下编译android4.0.4遇到的问题
这里总结下自己遇到的问题 jdk6安装,这个去苹果官网有 这里下载10.5的sdk https://github.com/phracker/MacOSX-SDKs/releases
- netframework webapi exceptionless
1.webapi项目 添加nuget exceptionless webapi 2.在exceptionless server端添加项目,注意key 3.修改api项目的webconfig &l ...
- [macOS] error when brew updating
I want to update the brew, then run brew update but unluckly, i got these error /usr/local/Library/b ...
- 对字符串md5加密
public String getMD5(String str) { try { // 生成一个MD5加密计算摘要 MessageDigest md = MessageDigest.getInstan ...
- 如何导出不带.svn的文件夹项目
实际工作中有需要导出项目,却含有大量的.svn文件夹,有以下几种方式导出: 一.TortoiseSVN导出 项目文件夹,右键->TortoiseSVN->导出(Export),勾选“导出无 ...
- [openjudge-动态规划]Maximum sum
题目描述 题目原文 描述 Given a set of n integers: A={a1, a2,-, an}, we define a function d(A) as below: d(A)=m ...
- winform中的dateTimePicker控件设置默认值为空
winform中的dateTimePicker控件设置默认值为空 第一步:设置Format的属性值为“Custom” 第二步:设置CustomFormat的属性值为空,需要按一个空格键
- Quartz Scheduler misfireThreshold属性的意义与触发器超时后的处理策略
Quartz misfireThreshold属性的意义与触发器超时后的处理策略. 在配置quartz.properties有这么一个属性就是misfireThreshold,用来指定调度引擎设置触发 ...
- html5+PHP,websocket无法连接的问题(Call to undefined function socket_create())
首先是配置文件的问题,打开extension=php_gd2.dll和extension=php_sockets.dll 扩展. 主要注意的是你当前系统使用的php版本和环境变量里面的php版本是否一 ...