来自:https://www.sourceware.org/pthreads-win32/manual/pthread_mutex_init.html
pthread_mutex_t类型的变量也可以静态初始化,
那么,pthread_mutex_t的类型是什么?
那就是那种.下面的实现通常是一个结构,你可以查看头文件,如果你真的关心你正在使用的库的具体实现,但这些细节与使用它无关,你只关心pthread_mutex_t类型.
pthread_mutex_t mymutex = PTHREAD_MUTEX_INITIALIZER;
Run Code Online (Sandbox Code Playgroud)
从pthreadtypes.h中,在我的Linux发行版中,其定义非常清楚,它是联合的typedef,如下所示:
/* Data structures for mutex handling. The structure of the attribute
type is not exposed on purpose. */
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
Run Code Online (Sandbox Code Playgroud)
您将要使用它作为其定义的类型,当然是pthread_mutex_t,因为此类型会因OS /发行版等而异。
| 归档时间: |
|
| 查看次数: |
16706 次 |
| 最近记录: |