什么意思是“原子的"?系统调用? [英] What means "atomic" system call?

查看:223
本文介绍了什么意思是“原子的"?系统调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 atomic 通常用于种族条件的上下文中,并且意味着诸如 consistency 确定性结果之类的东西根据多线程/多处理环境.没关系.但是最近我读到了Linux中的原子系统调用,却不明白 atomic 在这里实际上是什么意思,即如何这种 atomicity 已实现.这是否意味着该系统调用仅使用对资源的锁定(例如,目标文件inode上的open())还是还有其他内容,也许可以保证某些内核?我考虑禁用中断,但并非所有中断都可以禁用.可能就足够了,因为可以禁用内核使用的所有中断,而其他中断太重要,并且可以中断我们的 atomic 系统调用?

I know that atomic is usually used in the context of race condition and means something like consistency and determinism of the result according to multithreading/multiprocessing environment. That's ok. But recently I read about atomic system calls in Linux and didn't understand what does atomic actually mean here, i.e. how this atomicity is implemented. Does it mean that this system calls simply use locks on the resources (e.g. open() on the target file inode) or there is anything more, may be some kernel guarantees? I think about disabling interrupts but not all interrupts can be disabled. May be that's enough because all interrupts used by the kernel can be disabled and others are too important and can interrupt our atomic system call?

推荐答案

这确实取决于系统调用.引用man 3 read,它引用了posix编程手册:

That really depends on the system call. Citing man 3 read, which cites the posix programming manual:

I/O旨在成为普通文件和管道的原子, 先进先出原子表示单个操作中的所有字节 一起开始,最后一起结束,而无需交织在一起 其他I/O操作.这是终端的已知属性 不被接受,并且终端被显式(隐式地) 永久)排除,从而使行为不确定.这 其他设备类型的行为也未指定,但是 措辞旨在暗示未来的标准可能会选择 指定原子性(或不指定).

I/O is intended to be atomic to ordinary files and pipes and FIFOs. Atomic means that all the bytes from a single operation that started out together end up together, without interleaving from other I/O operations. It is a known attribute of terminals that this is not honored, and terminals are explicitly (and implicitly permanently) excepted, making the behavior unspecified. The behavior for other device types is also left unspecified, but the wording is intended to imply that future standards might choose to specify atomicity (or not).

很明显,这仅适用于IO操作.

Obviously, this only applies to IO operations.

这篇关于什么意思是“原子的"?系统调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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