Larbin源代码分析[6]LARBIN中线程处理类
一 線程類
larbin下的線程操作類,主要在mypthread.h中定義,實質上是利用宏定義,封裝了pthread.h中的系統調用。
一個進程可以有多個線程,每個線程都有自己的處理流程。
二 具體實現
typedef void* (*StartFun) (void *);
void startThread (StartFun run, void *arg);
startThread 函數實質上是 調用pthread_create 啟動一個新的線程。
//下面為線程同步的操作
#define mypthread_cond_init(x,y) pthread_cond_init(x,y)
#define mypthread_cond_destroy(x) pthread_cond_destroy(x)
#define mypthread_cond_wait(c,x,y) while (c) { pthread_cond_wait(x,y); }
#define mypthread_cond_broadcast(x) pthread_cond_broadcast(x)
//下面為線程互斥的操作
#define mypthread_mutex_init(x,y) pthread_mutex_init(x,y)
#define mypthread_mutex_destroy(x) pthread_mutex_destroy(x)
#define mypthread_mutex_lock(x) pthread_mutex_lock(x)
#define mypthread_mutex_unlock(x) pthread_mutex_unlock(x)
轉載于:https://www.cnblogs.com/zhoulinhu/archive/2011/10/24/2222794.html
總結
以上是生活随笔為你收集整理的Larbin源代码分析[6]LARBIN中线程处理类的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 统一命名规则
- 下一篇: div+css 你知道多少?值得一看