gpt4 book ai didi

locking - pthread_mutex_t 结构 : What does lock stand for?

转载 作者:行者123 更新时间:2023-12-01 23:56:21 27 4
gpt4 key购买 nike

我正在查看 pthreadtypes.h 文件中的 pthread_mutex_t 结构。 “__lock”代表什么?它就像分配给互斥锁的锁号吗?

typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
#if __WORDSIZE == 64
unsigned int __nusers;
#endif
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
#if __WORDSIZE == 64
int __spins;
__pthread_list_t __list;
# define __PTHREAD_MUTEX_HAVE_PREV 1
#else
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
#endif
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;

} pthread_mutex_t;

最佳答案

__lock struct __pthread_mutex_s成员(member)__data在 Linux 上用作 futex 对象。根据您正在查看的架构,以下许多细节可能会有所不同:

pthread_mutex_lock.c pthread 互斥锁的高级锁定函数的代码 - __pthread_mutex_lock() ,通常最终会调用 LLL_MUTEX_LOCK()以及 LLL_MUTEX_LOCK() 的定义和 friend ,他们最终调用 lll_lock()等,在 lowlevellock.h .
lll_lock()宏依次调用__lll_lock_wait_private() , 调用 lll_futex_wait() ,这使得 sys_futex系统调用。

关于locking - pthread_mutex_t 结构 : What does lock stand for?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23449508/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com