gpt4 book ai didi

linux - pthread_mutex 的 "default mutex attributes"是什么**

转载 作者:太空狗 更新时间:2023-10-29 12:30:16 25 4
gpt4 key购买 nike

pthread_mutex_init 等接口(interface)的手册页中,

int pthread_mutex_init(pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr);

它说“如果 attr 为 NULL,则使用默认的互斥属性...”,默认的互斥属性被多次提及,它也是The Linux Programming Interface 一书中提到过,但从来没有在任何地方详细解释,我用谷歌搜索没有结果。

有一个帖子what is the "attribute" of a pthread mutex? ,它提到“通常,默认值是一组合理的属性,但它可能因平台而异”,但这不是我想要的,我想要更多细节。

那么,默认互斥属性到底是什么?

最佳答案

pthread_mutexattr_t 是一种不透明类型(您永远不会直接修改它),可通过各种 pthread_mutexattr_get*()/set*() 函数访问。除非这些函数的文档指定了默认值,否则默认值取决于实现,您不能依赖特定值。

您可以点击 POSIX.1-2008 here 中各种 pthread_mutexattr_get*() 函数的链接。并查找默认值(当您为属性传递 NULL 时也适用)。这里有一些选择报价:

pthread_mutexattr_getprotocol() :

The default value of the attribute shall be PTHREAD_PRIO_NONE.

pthread_mutexattr_gettype() :

The default value of the type attribute is PTHREAD_MUTEX_DEFAULT.

pthread_mutexattr_getpshared() :

The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE.

pthread_mutexattr_getrobust() :

PTHREAD_MUTEX_STALLED ... This is the default value.

虽然非类型属性有点晦涩。

关于linux - pthread_mutex 的 "default mutex attributes"是什么**,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29624365/

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