jake1036

larbin源码分析(六) larbin中线程处理类

larbin源码分析(六) 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)


     

posted on 2011-06-13 17:23 kahn 阅读(745) 评论(0)  编辑 收藏 引用 所属分类: larbin源码分析


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理