pthread_mutex_init做了什么呢?

来源:互联网 发布:java闭包是什么 编辑:程序博客网 时间:2024/04/28 13:07

http://bbs.chinaunix.net/thread-1075085-1-1.html

撇开编码习惯的问题,pthread_mutex_t can init with zero value.
相当于给了一个 kind为 PTHREAD_MUTEX_DEFAULT的mutex.

  1. int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
  2. {
  3.   if (!mutex) return EINVAL;
  4.   if (attr && attr->pshared == PTHREAD_PROCESS_SHARED) return ENOSYS;

  5.   mutex->lock = 0;
  6.   mutex->recursion = 0;
  7.   mutex->kind = attr ? attr->kind : PTHREAD_MUTEX_DEFAULT;
  8.   mutex->owner = NOHANDLE;
  9.   mutex->event = mkevent(0, 0);
  10.   if (mutex->event < 0) return ENOSPC;
  11.   return 0;
  12. }
复制代码

0 0