【问题标题】:Recursive mutex with FSU Pthread implementation具有 FSU Pthread 实现的递归互斥锁
【发布时间】:2010-11-18 10:59:44
【问题描述】:

我想知道佛罗里达州立大学实施的 pthread 标准是否能够处理递归互斥锁。 不幸的是,关于 FSU 实现的文档相当差,并且没有提到将互斥体声明为递归的可能性。

尝试如下声明互斥锁:

pthread_mutex_attr mutex_attr;
pthread_mutexattr_init (&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex, NULL);

并使用 FSU pthreads 库进行编译,我得到了以下错误列表:

test.c:25: error: `pthread_mutex_attr' undeclared (first use in this function)
test.c:25: error: (Each undeclared identifier is reported only once
test.c:25: error: for each function it appears in.)
test.c:25: error: parse error before "mutex_attr"
test.c:27: error: `mutex_attr' undeclared (first use in this function)
test.c:28: error: `PTHREAD_MUTEX_RECURSIVE' undeclared (first use in this function)

尝试在我的机器上使用(非 FSU)pthread 实现编译相同的代码,它可以工作。

为了避免琐碎,我提前告诉您,默认情况下,POSIX 互斥锁不是递归的。

我是否应该得出结论,在 FSU 实现中无法使用递归互斥锁,还是有另一种方法可以实现这些(即另一种将互斥锁声明为递归的方法)?

【问题讨论】:

  • 类型是pthread_mutex_attr_t 注意_t。
  • 本,你是对的,实际上我写的代码只是试图获得编译器的输出。原始代码是正确的:)

标签: recursion pthreads mutex recursive-mutex


【解决方案1】:

不,FSU pthreads 实现不支持递归互斥锁。事实上,latest release 没有互斥类型的概念。除了缺少 PTHREAD_MUTEX_* 互斥类型名称之外,它还省略了用于操作互斥类型的 pthread_mutexattr_settype()pthread_mutexattr_gettype() 函数。

【讨论】:

  • 感谢 Jeremy,因此,考虑到这一点,我认为我应该修改应用程序的流程以避免锁嵌套。
猜你喜欢
  • 2010-09-16
  • 2011-07-20
  • 2012-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-06
  • 1970-01-01
相关资源
最近更新 更多