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 ...
随机推荐
- Cartographer源码阅读(8):imu_tracker
IMU的输入为imu_linear_acceleration 和 imu_angular_velocity 线加速和角速度.最终作为属性输出的是方位四元数. Eigen::Quaterniond ...
- Cartographer源码阅读(5):PoseGraph位姿图
PoseGraph位姿图 mapping2D::PoseGraph类的注释: // Implements the loop closure method called Sparse Pose Adju ...
- qrcode插件生成二维码
<!DOCTYPE html> <html> <head> <meta name="viewport" content="wid ...
- DOM_xss预备知识
http://xuelinf.github.io/2016/05/18/%E7%BC%96%E7%A0%81%E4%B8%8E%E8%A7%A3%E7%A0%81-%E6%B5%8F%E8%A7%88 ...
- latex 参考文献
https://blog.csdn.net/garfielder007/article/details/51628565 https://www.cnblogs.com/BUAAdaozhong/p/ ...
- 面试(I)
即时通讯 为什么要TCP连接建立3次? 假设是2次: 假如在第1次客户端向服务器端发送请求因为阻塞,客户端会再次给服务器端发送请求,这次服务器端和客户端建立了连接.这样双方就可以发送数据了,发送完以后 ...
- 修改mongodb(带仲裁节点的副本集)各机器端口
需求:因为端口调整,需要改变副本的备份集 1.查看当前的副本集信息 [root@localhost bin]# ./mongo 192.168.1.134:10001 repltest:PRIMARY ...
- vue elementui报错总结
1. 错误: TypeError: _self.$scopedSlots.default is not a function 原因:这是因为在v-for/v-if切换标签时,原本这些标签每一个都是独 ...
- JS设计模式(14)适配器模式
什么是适配器模式? 定义:将一个类的接口转换成客户希望的另外一个接口.适配器模式使得原本由于接口不兼容而不能一起工作的那些类可以一起工作. 主要解决:主要解决在软件系统中,常常要将一些"现存 ...
- Codeforces 17E Palisection - Manacher
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个串$s$询问,有多少对回文子串有交. 好像很简单的样子. 考虑能不能直接求,感觉有点麻烦.因为要考虑右端点在当前回文子串内还有区间包含 ...