3 ms·
The problem with locks on a non real time os is that the OS may decide to interrupt your thread while it's holding the lock. No matter how short that is. I do e
by Gibbon1 7y ago
The problem with locks on a non real time os is that the OS may decide to interrupt your thread while it's holding the lock. No matter how short that is. I do embedded I've had similar things happen when the 'lock' is held for just a few instructions.
Tip: If you suspect crap like this, adding spin delays will make it happen often enough to debug.
- proverbialbunny 7y agoBy any chance do you have any references or information on how to do this (adding a spin delay)? It sounds interesting. -thanks :)
- Gibbon1 7y agoIn C it's very simple volatile int cnt = 0x1000; while(cnt--) ;
- hoseja 7y agoI've grown so paranoid of optimizing compilers this wouldn't even cross my mind. But it is correct, right?
- AlbertoGP 7y agoNot OP, but the “volatile” qualifier should prevent the compiler from optimizing it out.
- Gibbon1 7y agoYeah should. Multicore super scalar processors make me nervous about my assumptions. I wouldn't put it past one of them to realize that the result is unused and nop it. It's always good to check.
- vemv 7y agoI see now, thanks!