Skip to content

Why system call slow?

1、从user space到kernel space,链路比较长

2、context change

参见modernescpp The Atomic Flag:

The interface of a std::atomic_flag is sufficient to build a spinlock. With a spinlock, you can protect a critical section similar to a mutex. But the spinlock will not passively wait in opposite to a mutex until it gets it mutex. It will eagerly ask for the critical section. So it saves the expensive context change in the wait state but it fully utilises the CPU: