POSIX取消点应该如何表现? [英] How are POSIX cancellation points supposed to behave?

查看:149
本文介绍了POSIX取消点应该如何表现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找的glibc / NPTL的实现取消点,并将其与POSIX,除非我弄错这是完全错误的。所使用的基本模式是:

I've been looking at glibc/nptl's implementation of cancellation points, and comparing it to POSIX, and unless I'm mistaken it's completely wrong. The basic model used is:

int oldtype = LIBC_ASYNC_CANCEL(); /* switch to asynchronous cancellation mode */
int result = INLINE_SYSCALL(...);
LIBC_CANCEL_RESET(oldtype);

据POSIX:

在取消请求作用而功能在通话过程中悬浮的副作用是相同的,可能在一个单线程程序中可以看出的副作用时对函数的调用由信号中断和给定函数返回[EINTR]。任何此类副作用发生被称为任何取消清理处理程序之前。

The side-effects of acting upon a cancellation request while suspended during a call of a function are the same as the side-effects that may be seen in a single-threaded program when a call to a function is interrupted by a signal and the given function returns [EINTR]. Any such side-effects occur before any cancellation cleanup handlers are called.

我的这段话的解读是,如果我叫打开,我可以期待它的或者的到被取消(与我的整个主题一起)它无法打开文件之前,的的返回一个有效的文件描述符,或-1 错误号价值,但从来没有创建一个新的文件描述符然后失去它变成了空白。在另一方面,取消点glibc的/ NPTL实现看起来允许的地方就在系统调用返回之后,但在取消请求时 LIBC_CANCEL_RESET 发生争用条件。

My reading of this passage is that if I call open, I can expect it either to get cancelled (along with my whole thread) before it fails to open a file, or to return a valid file descriptor or -1 and errno value, but never to create a new file descriptor then lose it into the void. On the other hand, the glibc/nptl implementation of cancellation points seems to allow for a race condition where the cancellation request occurs just after the syscall returns but before LIBC_CANCEL_RESET takes place.

我疯了,要么就是自己真的执行这个坏了吗?如果是这样,那么POSIX允许这样的行为坏了(这似乎使取消完全无法使用,除非你把它改手动),或者他们只是公然无视POSIX?

Am I crazy, or is their implementation really this broken? And if so, does POSIX allow such broken behavior (which seems to render cancellation completely unusable unless you defer it manually), or are they just blatantly ignoring POSIX?

如果这种行为实际上是在打破,什么来实现它没有这样一个竞争条件的正确方法?

If this behavior is in fact broken, what's the correct way to implement it without such a race condition?

推荐答案

这难道不是澄清了该标准的下一段:

Isn't this clarified in the next paragraph of the standard:

然而,如果该线程被挂起在
  取消点和事件
  它正在等待之前发生
  取消请求时,它采取行动
  是不确定是否
  取消请求采取行动或
  是否取消请求
  保持挂起和恢复线程
  正常执行。

However, if the thread is suspended at a cancellation point and the event for which it is waiting occurs before the cancellation request is acted upon, it is unspecified whether the cancellation request is acted upon or whether the cancellation request remains pending and the thread resumes normal execution.

这意味着这场比赛的条件是完全合法的行为。

Which implies that this race condition is perfectly legal behaviour.

这篇关于POSIX取消点应该如何表现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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