Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I guess you're assuming the compiler will issue an "increment" instruction for the ++, and that instruction is atomic.

It's not a great coding practice. Move to a different processor (this happens!) and your code turns into a load-add-store, gets interrupted halfway through, and you scratch your head for a while about the mysterious and flaky FIFO failures.

Been there. At least a gesture towards an atomic operation would be nice, when you have data shared between interrupt and non-interrupt code.



How about putting

#if !defined(__AVR__) && !defined(__MSP430__)

#warning "Fix this FIFO - ++/-- possibly not atomic!"

#endif

into the header of that thingy then. Save work on small uCs, and be warned when moving it somewhere else.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: