具有 FSU Pthread 实现的递归互斥体
我想知道佛罗里达州立大学的 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 实现中使用递归互斥锁,或者有其他方法可以实现这些(即将互斥锁声明为递归的另一种方法)?
I am wondering whether the Florida State University implementation of the pthread standard is, by any chance, able to handle the recursive mutexes.
Unfortunately the documentation about the FSU implementation is rather poor, and it does not mention of the possibility or not to declare a mutex as recursive.
Trying to declare a mutex as follows:
pthread_mutex_attr mutex_attr;
pthread_mutexattr_init (&mutex_attr);
pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&mutex, NULL);
and compiling using the FSU pthreads library, I got this list of errors:
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)
Trying to compile the same code with the (non-FSU) pthread implementation on my machine, it works.
To avoid trivialities, I tell you in advance that, by default, the POSIX mutexes are not recursive.
Should I conclude that there is no way to make use of recursive mutexes with the FSU implementation, or there is another way to achieve these (i.e. another way to declare a mutex as recursive)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,FSU pthreads 实现不支持递归互斥体。事实上,最新版本没有互斥类型的概念。除了缺少
PTHREAD_MUTEX_*
互斥体类型名称之外,它还省略了用于操作互斥体类型的pthread_mutexattr_settype()
和pthread_mutexattr_gettype()
函数。No, the FSU pthreads implementation does not support recursive mutexes. In fact, the latest release has no notion of mutex types. In addition to lacking the
PTHREAD_MUTEX_*
mutex type names, it also omits thepthread_mutexattr_settype()
andpthread_mutexattr_gettype()
functions used to manipulate the mutex type.