Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CPU Relax instruction and C++11 primitives

Tags:

I've noticed that many lockless algorithms implemented using OS-specific primitives, such as the spin locks described here (which use Linux-specific atomic primitives) often make use of a "cpu relax" instruction. With GCC, this can be achieved with:

asm volatile("pause\n": : :"memory");

Specifically, this instruction is often used in the body of while loop spin locks, while waiting for a variable to set to a certain value.

C++11 doesn't seem to provide any kind of portable "cpu_relax" type instruction. Is there some reason for this? And does the "pause" statement actually accomplish anything useful?

Edit:

Also, I'd ask: why did the C++11 standards committee not decide to include a generic std::cpu_relax() or whatever? Is it too difficult to guarantee portability?