具有 FSU Pthread 实现的递归互斥体

发布于 2024-10-02 17:59:49 字数 965 浏览 3 评论 0原文

我想知道佛罗里达州立大学的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2024-10-09 17:59:49

不,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 the pthread_mutexattr_settype() and pthread_mutexattr_gettype() functions used to manipulate the mutex type.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文