5 ms·
When would you want a loop that does not terminate and does not perform I/O, read/write a volatile, synchronize with another thread, or perform an atomic operat
by charleslmunger 3y ago
When would you want a loop that does not terminate and does not perform I/O, read/write a volatile, synchronize with another thread, or perform an atomic operation?
- ryao 3y agoOne time the heat at my place went out and I wanted to repurpose my machine as a space heater. In such a scenario, such a loop is desirable. Termination can be done by the operating system.
- macksd 3y agoI have a System76 Serval and I highly recommend it, especially for your use case.
- maximus-decimus 3y agorelevant xkcd https://xkcd.com/1172/ https://xkcd.com/1172/
- ryao 3y agoIt is a very important feature. :P
- bit-hack 3y agoa busy loop waiting for an interrupt to fire?
- sweetjuly 3y agoThis is reasonable, but for the sake of your power budget I hope you use a wait-for-interrupt instruction instead rather than just spinning :)
- deleted 3y ago[deleted]
- isopede 3y agoThis happens regularly in the embedded space. Exception and fault handlers, for example.
- vbezhenar 3y agoFor example when my algorithm is driven by interrupts and "user code" need to do nothing. One approach is to use something like WFI instruction in the loop, but this instruction has its own issues, for example I experienced issues with attached gdb on some chinese STM32 clones. Using busy loop worked just fine. Using "unused" volatile also works, but it incurs SRAM traffic, which might slow down DMA and cause other effects. So ideally it should be simple empty loop compiled to `b .` instruction (jump to itself). Another infinite loop usage is for abort() or exit() handler, as a crash place. For this use-case, using "unused" volatile does not cause issues, because device is already crashed, however it still feels wrong.