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?
That really depends on the system call. Citing man 3 read
, which cites the posix programming manual:
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).
Obviously, this only applies to IO operations.
来源:https://stackoverflow.com/questions/29185304/what-means-atomic-system-call