多线程编程指南

sema_init 语法

#include <thread.h>



int sema_init(sema_t *sp, unsigned int count, int type,

    void *arg);

type 可以是以下值之一:

多个线程决不能同时初始化同一个信号。不得对其他线程正在使用的信号重新初始化。

进程内信号

#include <thread.h>



sema_t sp;

int ret;

int count;

count = 4;



/* to be used within this process only */

ret = sema_init(&sp, count, USYNC_THREAD, 0); 

进程间信号

#include <thread.h>



sema_t sp;

int ret;

int count;

count = 4;



/* to be used among all the processes */

ret = sema_init (&sp, count, USYNC_PROCESS, 0);