信号如何与序列点相互作用? [英] How do signals interact with sequence points?

查看:31
本文介绍了信号如何与序列点相互作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C89 标准规定:

At sequence points volatile objects are stable in the sense that previous
evaluations are complete and subsequent evaluations have not yet occurred.

C89 标准还规定:

When the processing of the abstract machine is interrupted by receipt of a
signal, only the values of objects as of the previous sequence point may be
relied on.

这些要求让我很困惑,因为我无法想象他们会如何实际落实.我只对 x86-64 有一个初步的了解汇编程序,但这是我脑子里闪过的东西.假设我们有一个易变的结构,它有很多千字节大.如果复制现有的struct 到 C 中的这个易失性结构中,然后生成的机器代码可能非常大.现在,假设大量的机器代码是执行,并且系统上的某些 shell 执行kill"命令过程,引起一些信号的升高.我的理解(或者更确切地说是我的猜测)是该过程将在复制中间中断,导致对 volatile 的要求被破坏,并导致结构从任何信号处理程序的观点.

These requirements leave me confused, because I can't imagine how they would actually be implemented. I only have a rudimentary understanding of x86-64 assembler, but here's what is running through my head. Let's say that we have a volatile struct, and it's many kilobytes large. If you copy an existing struct into this volatile struct in C, then the resulting machine code might be very large. Now, let's say that this large amount of machine code is executing, and some shell on the system executes the "kill" command on the process, causing the raising of some signal. My understanding (or rather my guess) is that the process would be interrupted in mid-copy, causing the requirement on volatile to be broken, and causing the struct be malformed from the perspective of any signal handler.

显然事情并不是这样运作的,但是它们实际上是如何运作的工作?为了论证,请随意假设平台是 x86-64或 x86 Linux、Windows、OS X 或其他一些常见的 UNIX.

Obviously things don't actually work like this, but then how do they actually work? For the sake of argument feel free to assume that the platform is x86-64 or x86 Linux, Windows, OS X, or some other common UNIX.

推荐答案

在序列点上,易失性对象在之前的意义上是稳定的评估已完成,尚未进行后续评估.

At sequence points volatile objects are stable in the sense that previous evaluations are complete and subsequent evaluations have not yet occurred.

这不会被违反,因为中断不是序列点.该规则仅描述在序列点"发生的情况.如果我们在序列点 A 之后和序列点 B 完成之前被中断,我们就不是在"序列点 A 或序列点 B.

This wouldn't be violated, since the interruption is not a sequence point. This rule only describes what happens "at sequence points". If we are interrupted after sequence point A and before sequence point B completes, we aren't "at" sequence point A or sequence point B.

当抽象机的处理因收到一个信号,只有前一个序列点的对象的值可能是依赖.

When the processing of the abstract machine is interrupted by receipt of a signal, only the values of objects as of the previous sequence point may be relied on.

这不会被违反.如果我们在序列点 A 和 B 之间被打断,比如在中间复制中,则可以依赖在序列点 A 所做的所有更改.他们完成了.

This wouldn't be violated. If we are interrupted between sequence points A and B, say in mid copy, all the changes made at sequence point A can be relied on. They're done.

能够依赖先前的修改并不意味着您不会看到后续修改的任何效果.值是稳定的,直到未来的一些代码可以修改它们.

Being able to relying on a previous modification doesn't mean that you won't see any effects of a subsequent modification. Values are stable until some future bit of code can modify them.

所以明显的实现不会违反任何一个要求.

So the obvious implementation doesn't violate either of the requirements.

这篇关于信号如何与序列点相互作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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