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 ...
随机推荐
- 【UML】NO.51.EBook.5.UML.1.011-【UML 大战需求分析】- 时序图(Timing Diagram)
1.0.0 Summary Tittle:[UML]NO.51.EBook.1.UML.1.011-[UML 大战需求分析]- 时序图(Timing Diagram) Style:DesignPatt ...
- MySQL Backup mysqldump 常用选项与主要用法
The mysqldump client utility performs logical backups, producing a set of SQL statements that can be ...
- VS2015 新建 ASP.NET Web应用程序, 此模板尝试加载程序集‘Microsoft.VisualStudio.Web.Project’, 解决方案
下载并安装Azure的SDK即可:
- 竖倾斜ScrollView
using UnityEngine; using UnityEngine.EventSystems; public class ObliqueScroll : MonoBehaviour,IDragH ...
- Java 五大原则
1.单一职责 不论是在设计类,接口还是方法,单一职责都会处处体现,单一职责的定义:我们把职责定义为系统变化的原因.所有在定义类,接口,方法的时候.定义完以后再去想一想是不能多于一个的动机去改变这个类, ...
- vuejs服务端渲染更好的SEO,SSR完全指南Nuxt.js静态站生成器
vuejs服务端渲染更好的SEO,SSR完全指南Nuxt.js静态站生成器SSR 完全指南https://cn.vuejs.org/v2/guide/ssr.html在 2.3 发布后我们发布了一份完 ...
- IP通信基础学习第二周
此周的课程学习应该算是我对此科目真正学校生涯的开始吧,尽管我对该科目仍感到很陌生. 课程一开头,老师就给我们简单的介绍了网络的定义.发展及其分类,重点讲了网络拓扑结构及其在局域网上具体的分层情况.该部 ...
- GoldenGate使用SQLEXEC和GETVAL实现码表关联
使用OGG中的SQLEXEC参数,可以执行SQL语句或存储过程,再加上@GETVAL函数,可以在目标端获取源表没有的字段值.比如,源端有一个事实表和一个代码表COUNTRY_CODES,代码表中有两个 ...
- 02:openf-falcon安装
open-falcon其他篇 目录: 1.1 安装open-falcon环境准备 1.2 部署open-falcon后端 1.2.1 agent配置文件 1.2.2 transfer(数据上报) 1. ...
- [C++ Primer Plus] 第4章、复合类型(一)程序清单——指针new和delete
程序清单4.1 #include<iostream> using namespace std; void main(){ ]; yams[]=; yams[]=; yams[]=; ]={ ...