mirror of
https://github.com/ETLCPP/etl.git
synced 2026-06-15 16:36:03 +08:00
881 B
881 B
| title |
|---|
| infinite_loop |
{{< callout type="info">}}
Header: infinite_loop.h
{{< /callout >}}
A portable infinite loop that will not be optimised away by the compiler.
Before C++26, an empty infinite loop without side effects is considered undefined behaviour and may be optimised away. This utility uses a compiler memory barrier to prevent that optimisation.
See P2809R1 for background.
Function
[[noreturn]] inline void etl::infinite_loop()
Description Enters an infinite loop that is guaranteed not to be removed by the compiler.
On GCC and Clang this is achieved with an inline assembly memory clobber.
On MSVC this uses _ReadWriteBarrier().
Example
#include <etl/infinite_loop.h>
int main()
{
// Initialise hardware...
etl::infinite_loop();
}