gpt4 book ai didi

attributes - pthread互斥锁的 “attribute”是什么?

转载 作者:行者123 更新时间:2023-12-03 10:38:13 26 4
gpt4 key购买 nike

函数pthread_mutex_init允许您指定指向属性的指针。但是我还没有找到关于pthread属性是什么的很好的解释。我一直只是提供NULL。这个论点有用吗?

该文档,对于那些忘记它的人:

PTHREAD_MUTEX_INIT(3) BSD Library Functions Manual
PTHREAD_MUTEX_INIT(3)

NAME pthread_mutex_init -- create a mutex

SYNOPSIS

 #include <pthread.h>

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

DESCRIPTION The pthread_mutex_init() function creates a new mutex, with attributes specified with attr. If attr is NULL, the default attributes are used.

最佳答案

找到该信息的最佳位置是POSIX标准页面。
NULL互斥锁属性为您提供了实现定义的默认属性。如果您想知道可以使用属性做什么,请查看following reference并遵循pthread_mutexattr_*部分中的SEE ALSO链接。通常,默认值是一组合理的属性,但是在不同的平台上它可能会有所不同,因此我更喜欢显式地创建具有已知属性的互斥对象(为可移植性更好)。

这是针对标准1003.1-2008第7版的。起点是here。单击左下角的Headers将允许您导航到特定功能(包括pthreads.h)。

这些属性允许您设置或获取:

  • type(死锁,检测死锁,递归等)。
  • robustness(当您获取互斥锁并且原始所有者在拥有该互斥锁时死亡)。
  • process-shared attribute(用于跨进程边界共享互斥锁)。
  • protocol(当较高优先级的线程需要互斥量时,线程在优先级方面的行为)。
  • priority ceiling(运行关键部分的优先级,一种防止优先级倒置的方法)。

  • 并且,为了完整起见,还有 init and destroy calls,它与特定属性没有直接关系,但用于创建它们。

    关于attributes - pthread互斥锁的 “attribute”是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4252005/

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