码迷,mamicode.com
首页 >  
搜索关键字:pthread_mutex    ( 196个结果
设计模式
1. 单例模式 (多线程下) a. 饿汉式 1 template<class T> 2 class Singleton { 3 public: 4 static T* get_instance() { 5 if( _instance == NULL ) { 6 pthread_mutex_lock( ...
分类:其他好文   时间:2016-04-21 15:08:06    阅读次数:134
线程同步与互斥
1#include<stdio.h> 2#include<pthread.h> 3 4staticintcount=0; 5staticpthread_mutex_tlock=PTHREAD_MUTEX_INITIALIZER; 6void*pthread(void*arg) 7{ 8inttmp=0; 9inti=5000; 10while(i--) 11{ 12pthread_mutex_lock(&lock); 13tmp=count; 14printf("thisi..
分类:编程语言   时间:2016-04-17 18:01:42    阅读次数:250
pthread读文本文件
#include<pthread.h> #include<fstream> #include<iostream> #include<string> #include<vector> usingnamespacestd; #defineLINE_PER_THREAD1024 pthread_mutex_tcount_mutex=PTHREAD_MUTEX_INITIALIZER; structparam{ vector<string>..
分类:其他好文   时间:2016-04-17 09:08:11    阅读次数:138
两线程竞争修改全局变量
#include<pthread.h> #include<iostream> usingnamespacestd; intglobal=0; #defineNUMTHREADS2 pthread_mutex_tmutexnum; structthread_data{ intidx; }; structthread_datathread_data_array[NUMTHREADS]; void*assign_value(void*param){ structthread_da..
分类:编程语言   时间:2016-04-16 11:02:51    阅读次数:121
POSIX多线程程序设计_流水线工作例程
#include #include "errors.h" typedef struct stage_tag{ //流水线的工作单元结构体 pthread_mutex_t mutex; //保护当前工作单元数据的互斥锁 pthread_cond_t avail; //等待当前工作单元存储数据可用的条件变量 pthread_cond_t ready; //等待当前工作单元可处理...
分类:编程语言   时间:2016-03-26 07:33:59    阅读次数:255
linux第13天 生产者与消费者
pthread_cond_t my_condition = PTHREAD_COND_INITIALIZER; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; // 互斥锁和条件等待 解决生产者和消费者模型 条件等待模型//socket连接池。。
分类:系统相关   时间:2016-03-17 14:39:39    阅读次数:175
pthread_mutex_lock()、pthread_mutex_unlock()
pthread_mutex_lock() pthread_mutex_unlock() 当该函数返回时,该互斥锁已经被锁定。线程调用该函数让互斥锁上锁,如果该互斥锁已被另一个线程锁定和拥有,则调用该线程将阻塞,直到该互斥锁为可用为止; 头文件为: #include <pthread.h> pthre
分类:其他好文   时间:2016-03-11 11:47:47    阅读次数:145
linux 线程备忘
三种线程同步机制 ?互斥锁 ?信号量 ?条件变量 pthread_t thread_id; 主要函数 pthread_create(),pthread_exit(),pthread_join(),pthread_cancel() pthread_mutex_t mutex; 互斥锁主要包括下面的基本
分类:编程语言   时间:2016-03-03 01:21:09    阅读次数:177
一个简单线程池的实现---需进一步完善
1.定义一个任务结构体,和一个线程池结构体 struct task{ void *(*p)(void*);//需要实现的函数; void *arg;//函数所带的参数 struct task *next;};struct pthread_pool{ pthread_mutex_t mutex;//线
分类:编程语言   时间:2016-03-01 22:15:26    阅读次数:230
Linux 多线程编程 实例 2
编写一个程序,开启3个线程,这3个线程的ID分别为A、B、C,每个线程将自己的ID在屏幕上打印10遍,要求输出结果必须按ABC的顺序显示;如:ABCABC….依次递推。使用条件变量来实现:#include #include #include static pthread_mutex_t mtx=PT...
分类:编程语言   时间:2016-01-24 18:14:30    阅读次数:144
196条   上一页 1 ... 7 8 9 10 11 ... 20 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!