pthread更改全局变量
2016-04-15 02:28
246 查看
#include <pthread.h> #include <iostream> using namespace std; int global = 0; void * assign_value(void *param){ global = 3; } int main(){ pthread_t thread; pthread_create(thread, NULL, assign_value, (void *) nullptr); pthread_join(thread, NULL); cout << global << endl; return 0; }结果输出为3,如果不加pthread_join(thread,NULL)的话,输出为0。这里,pthread_join只有当thread线程结束工作时才返回。
相关文章推荐
- 使用 golang 实现类似 pthread_barrier_t 语义的 barrier 对象 3ff0
- Linux C Phread 入门1---线程创建
- POSIX 线程库功能接口与知识点汇总
- [转载]Pthreads mutex VS Pthreads spinlock
- C++爱好者博客
- 信号量,互斥锁实现 生产者-消费者模式
- 多线程编程之信号量
- pthread线程学习笔记一
- 多线程之互斥锁
- pthread学习笔记
- 基于pthread的线程池,C++实现
- Pthreads多线程编程(1)
- iOS多线程之Pthread/NSthread
- IO多路复用(select)多线程实现点对点聊天
- pthread_mutex_lock用法
- pthread线程编程常用API
- 一个有错的文章但是仍然有很强的学习点的文章
- cocos2d-x pthread 多线程简单实现
- pthread_create()给创建的线程传递参数
- iOS 多线程 pthread的简单使用——iOS 编码复习(五)(多线程3)