什么是"属​​性"的Pthread互斥? [英] what is the "attribute" of a pthread mutex?

查看:134
本文介绍了什么是"属​​性"的Pthread互斥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数调用pthread_mutex_init允许你指定一个指向属性。但是,我还没有找到什么PTHREAD属性是一个很好的解释。我一直都只是提供NULL。有没有使用这种说法?

的文档,对于那些你们谁忘记了:


  

调用pthread_mutex_init(3)的BSD库
  功能手册结果
  调用pthread_mutex_init(3)


  
  

NAME
       调用pthread_mutex_init - 创建一个互斥体


  
  

概要

 的#include< pthreads.h中> INT
 调用pthread_mutex_init(pthread_mutex_t *限制互斥体,
     常量pthread_mutexattr_t *限制attr)使用;


  
  

描述
       该调用pthread_mutex_init()函数创建一个新的互斥体,带有属性
  指定
       与ATTR。如果attr为NULL,则默认属性被使用。



解决方案

要找到这些信息的最佳位置是从POSIX标准页。

A NULL 互斥锁属性为您提供了一个实现定义的默认属性。如果你想知道你可以用属性做什么,请查看以下引用并按照 pthread_mutexattr _在请参见部分* 链接。通常,默认是一个明智的属性集,但它可能在平台之间有所不同,所以我preFER明确创建与已知属性互斥体(便携更好)。

这是为标准,1003.1-2008的问题7。该起点是这里。在左下方点击标题将允许您浏览到特定的功能(包括 pthreads.h

属性让你设置或获取:


  • 的<一个href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_gettype.html#\">type (死锁,死锁检测,递归,等等)。

  • 的<一个href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getrobust.html#\">robustness (当你获得一个互斥体,并同时具有它原来的主人死了,会发生什么)。

  • 的<一个href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getpshared.html#\">process-shared属性(共享跨进程互斥)。

  • 的<一个href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html#\">protocol (如何线程的行为时,高优先级的线程想要互斥量优先的条款)。

  • 的<一个href=\"http://www.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprioceiling.html#\">priority天花板(在此关键部分将运行优先,preventing优先级反转的一种方式)。

和,完整性,还有的 init和destroy电话为好,不能直接的与特定的属性,但用于创建它们。

The function pthread_mutex_init allows you to specify a pointer to an attribute. But I have yet to find a good explanation of what pthread attributes are. I have always just supplied NULL. Is there a use to this argument?

The documentation, for those of you who forget it:

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.

解决方案

The best place to find that information is from the POSIX standards pages.

A NULL mutex attribute gives you an implementation defined default attribute. If you want to know what you can do with attributes, check out the following reference and follow the pthread_mutexattr_* links in the SEE ALSO section. Usually, the default is a sensible set of attributes but it may vary between platforms, so I prefer to explicitly create mutexes with known attributes (better for portability).

This is for issue 7 of the standard, 1003.1-2008. The starting point for that is here. Clicking on Headers in the bottom left will allow you to navigate to the specific functionality (including pthreads.h).

The attributes allow you to set or get:

  • the type (deadlocking, deadlock-detecting, recursive, etc).
  • the robustness (what happens when you acquire a mutex and the original owner died while possessing it).
  • the process-shared attribute (for sharing a mutex across process boundaries).
  • the protocol (how a thread behaves in terms of priority when a higher-priority thread wants the mutex).
  • the priority ceiling (the priority at which the critical section will run, a way of preventing priority inversion).

And, for completeness, there's the init and destroy calls as well, not directly related to a specific attribute but used to create them.

这篇关于什么是&QUOT;属​​性&QUOT;的Pthread互斥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆