News for hackers. Stuff that matters.
Re:UART Receive Buffering by shabble on Friday June 12, 2015 @01:51AM (#9704278)
Why isn't volatile sufficient here? If they were both modifying the same variable, I can see how

A:read Ax; (Interrupt: B:read Bx; B:write Bx+1; return); A: write Ax+1 # (wrong!)

could occur. But the only error I can see here is that sometimes put() might fail thinking there is overflow when there's maybe one space left.

Am I missing something?

(Further investigation: This[1] thread suggests you can run into problems if your counter type is larger than the native ALU size, because the interrupt could occur midway through your increment operation. But here the size_t is 16 bits, so that should 't be a problem?)

[1] http://www.embeddedrelated.com/showthread/msp430/20400-1.php

Re:UART Receive Buffering by cnvogel on Friday June 12, 2015 @05:12AM (#9704766)
Also the update of the write pointer could be reordered to occur before storage of the actual data flushed to the buffer.

      e.g.
      buf[volatile_write_ptr] = c
      volatile_write_ptr++;
might occur the other way 'round for the code that is reading from buf[].

For typical "simple" single processor controllers this will not be an issue, though, and "volatile"+spinlocks/disenable-enable-interrupts will work just fine.