#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的更多相关文章

  1. NPTL vs PThread

    NPTL vs PThread POSIX threads (pthread) is not an implementation, it is a API specification (a stand ...

  2. Linux Pthread 深入解析(转-度娘818)

    Linux Pthread 深入解析   Outline - 1.线程特点 - 2.pthread创建 - 3.pthread终止         - 4.mutex互斥量使用框架         - ...

  3. 创建线程方式-pthread

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  4. Linux 下子线程 exit code 在主线程中的使用

    Linux线程函数原型是这样的: void* thread_fun(void* arg) 它的返回值是 空类型指针,入口参数也是 空类型指针.那么线程的 exit code 也应该是 void * 类 ...

  5. pthread clean up

    https://www.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part4/ http://www.cnblogs.com/xfi ...

  6. 【转】用Pthread创建线程的一个简单Demo

    一.我们直接在COCOS2D-X自带的HelloWorld工程中添加代码.首先将Pthread的文件包含进来包括lib文件.在HelloWorld.cpp中引入头文件和库. #include &quo ...

  7. pthread小结

    参考1 https://computing.llnl.gov/tutorials/pthreads/ 参考2 http://man7.org/linux/man-pages/man7/pthreads ...

  8. pthread 线程立即取消的两种方法

    1.相关函数介绍 a. int pthread_cancel(pthread_t thread) 1发送终止信号给thread线程,如果成功则返回0,否则为非0值.发送成功并不意味着thread会终止 ...

  9. NDK中使用pthread多线程中自己写的一个BUG

    在使用pthread进行NDK中的多线程开发时,自己写了一个BUG, void *darkGrayThread(void *args) { ThreadParam *param = (ThreadPa ...

随机推荐

  1. Mac系统下 PHP7安装Swoole扩展 教程

    转载自 https://www.fujieace.com/php/php-extensions/swoole.html 今天我用的PHP版本是:PHP7.1 环境依赖: php-5.3.10 或更高版 ...

  2. PowerBI新功能: 自定义数据连接器(Data Connector)

    你是不是觉得原有的数据连接器(Data Connector)列表,就像女人的衣柜,总少那么一件你想要的呐? 现在,你的救星来了!你可以自己造一个了! Power BI的数据连接器(Data Conne ...

  3. autoMapper的介绍

    .NET的DTO映射工具AutoMapper 分类: 多层架构 DTO .NET2012-08-11 10:27 2466人阅读 评论(0) 收藏 举报 原文:https://github.com/A ...

  4. QCon2019全球软件开发大会广州站即将来袭

    QCon广州2019|全球软件开发大会 会议时间:2019-05-25 08:00至 2019-05-28 18:00结束 会议地点: 广州  广州万富希尔顿酒店  中国广州市白云区云城东路515-5 ...

  5. MFC 的资源文件 就是那个后缀名是 .rc的那个

    参考: http://blog.csdn.net/zgrjkflmkyc/article/details/16897881 http://www.oschina.net/question/565065 ...

  6. st2_057

    http://vulapps.evalbug.com/s_struts2_s2-057/ 这大概是全网复现st2-057环境最简单的操作了. 不过首先,你需要安装过docker,安装方法参考官方文档h ...

  7. GALV_maptravel研究分析(1)

    强大的地图传送式插件~~ 我以自带demo进行分析,本篇地图Init setting map 1.---------------------------------- 实例 创建地图 Galv.MAP ...

  8. Vue系列之 => webpack基础使用

    webpack安装方式 1,运行 npm i webpack -g 全局安装. 2,在项目根目录中运行 npm i webpack --save-dev 安装到项目依赖中 项目目录 进入src运行, ...

  9. Install rapyuta Robot Cloud Engine on Ubuntu14.04

    # -Rapyuta-installation-in-Ubuntu14.04-LTS-Trusty-This gzip folder is a tested version which can ins ...

  10. mybatis常见问题和错误

    1. jdbc java type 映射关系 1) mysql的text 在mybatis中使用varchar类型 2. mybatis常见的错误 3.There is no getter for p ...