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.