It is very tempting to reach for Interrupt Disable and/or Scheduler Lock when programming in an embedded RTOS system…
Why? They are so light… If you look under the hood, a scheduler lock if built out of two pairs of interrupt disable / enable blocks.
A mutex is built out of two pairs of scheduler lock/unlocks.
And you have to declare a mutex and initialize it and ….
How often have you heard in a review “we’re just going to do a tiny bit of work, we can do it in a sched lock or with interrupts disabled…”?
Often such code will not port to any multicore future.
The more I hear this phrase, “we’re just going to do a tiny bit of work”, I hear “I just want to do an atomic operation, that should have very very low contention rates”.
The more I think this, the more I think, hmm, if only we really understood and had standard idioms around atomic __builtins, we probably would hardly ever use interrupt disable or sched lock again.
It is time old dogs started learning new tricks.