volatile vs memory barrier for interrupts

前端 未结 1 413
北恋
北恋 2021-01-14 02:02

Let x and y be variables that are shared between main code and interrupt code.

My idea of volatile is that it is only and alwa

相关标签:
1条回答
  • 2021-01-14 02:50

    Memory barriers instead of volatile are fine. Linux kernel developers prefer it that way

    There are a few things to watch out for.

    • Move the barrier after disabling interrupts. Interrupts tend to happen at the worst times.
    • You need a second memory barrier before enabling interrupts, for variables that are written in the main program, and read in the interupt handler.
    • Disabling interrupts is not enough in a multiprocessor/multicore system, it doesn't prevent another core from running.
    • Needless to say, interrupts should not be disabled for extended periods of time, as it can prevent some hardware drivers from functioning.
    0 讨论(0)
提交回复
热议问题