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 ...
随机推荐
- Linux下安装jieba
Jieba代码对 Python 2/3 均兼容 * 全自动安装:`easy_install jieba` 或者 `pip install jieba` / `pip3 install jieba` * ...
- CentOS 7静默安装Oracle 11g R2数据库软件
之前安装Oracle 11g R2数据库软件都是建立在图形界面上的,不过现在大部分服务器上都没有安装图形界面.图形界面安装较为方便,安装选项清晰,步骤明确,但Oracle还支持另一种安装方式,就是通过 ...
- SystemParametersInfo调置壁纸、屏幕保护程序
应用SystemParametersInfo函数可以获取和设置数量众多的windows系统参数.这个小程序就是运用了SystemParametersInfo函数来设置桌面的墙纸,而且程序可以让我们选择 ...
- shell中输出日期的一个函数
开始 function T () { date '+%F %T.%N' } 结束
- 再解炸弹人,dfs&bfs
输入样例: 13 13 3 3##############GG.GGG#GGG.####.#G#G#G#G##.......#..G##G#.###.#G#G##GG.GGG.#.GG##G#.#G# ...
- 2440 裸机学习 点亮LED
1.首先需要知道 led 是受哪一个gpio口控制 从上图可以看出,两个led灯是受GPF4 GPF5控制的,低电平有效. 2.怎么控制GPF4 GPF5 通过2440的芯片手册可以看出,需要设置GP ...
- catch data
抓取一些有反爬机制的website 喜马拉雅 每天都有-动态class 通过网络请求
- 简单js 切换左侧栏目的样式
这是html代码,里面写了left.html <div id='mydiv'> <a class='qwe'>1</a> <a class='qwe'> ...
- 剑指offer(45)扑克牌顺子
题目描述 LL今天心情特别好,因为他去买了一副扑克牌,发现里面居然有2个大王,2个小王(一副牌原本是54张^_^)...他随机从中抽出了5张牌,想测测自己的手气,看看能不能抽到顺子,如果抽到的话,他决 ...
- 剑指offer(50)数组中重复的数字
题目描述 在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果输入长度为 ...