sergio masci wrote: > On Sun, 2 Aug 2009, Dave Tweed wrote: > > My point was, that if you add a simple boolean flag to the FIFO > > structure, you CAN completely fill it, and this actually has negligible > > impact on the overall code size, and does NOT affect its thread-safe > > properties. > > Ok, so please show how you would do this. Oh, no, that would be telling! :-) I've already written this up as part of the EQ quiz for Circuit Cellar #230 (September 2009), so you'll be able to read my solution there by the end of the month. In the meantime, give it some thought. It's actually quite straightforward. > As a mater of interest what limitted expression-handling capabilities do > you see this code trying to get around (with the use of the temporary > variable). Well, you wrote it with only one operation per line. With the "proc" keyword, it wasn't immediately obvious that this was C code. I was also suspicious of storing the length, head and tail of the FIFO in the array with the data. You wouldn't ordinarily do that unless a language limitation was forcing you to. I just assumed it was some personal language of yours that was even lower-level than C, and I guessed that it was either easily translatable to assembly, or that it had come from assembly to begin with. In C, of course, you would simply write something like: tail = (tail + 1) % FIFO_SIZE; Or, if your compilier isn't smart enough to optimize the % operator: tail = (tail + 1 == FIFO_SIZE) ? 0 : tail + 1; Either of these is perfectly thread-safe; no standards-compliant compiler would turn either statement into multiple assignments to tail. -- Dave Tweed -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist