Ruankao Embedded System Designer (Intermediate) study materials
Ruankao Embedded System Designer (Intermediate) study resources

A ring buffer has two ownership transitions

Ruankao Embedded System Designer (Intermediate) · Put your knowledge to work in context.

All case studies

A ring buffer has two ownership transitions

A fictional firmware exercise uses a ring buffer between one interrupt producer and one task consumer. The producer writes received bytes and advances a head index; the consumer reads bytes and advances a tail index. The buffer and indexes are visible in the source, but the actual atomic access width, memory-ordering rules and full-versus-empty convention have not been documented. A developer marks every variable volatile and declares the concurrency problem solved. Test logs show occasional repeated bytes after an index wrap. The team needs a defined ownership and synchronization protocol before choosing a code remedy. This is a conceptual review rather than a request to change a live communications controller, and no assumption is made that every processor, compiler or RTOS provides the same ordering guarantees.

1. Why is volatile alone insufficient evidence?

Read the worked answer

Volatile does not generally provide atomic read-modify-write, mutual exclusion or all required cross-context ordering. Correctness depends on how payload and index publication are ordered, what accesses are atomic and which side owns each state transition.

2. What should the test and design specify?

Read the worked answer

State capacity, index width, wrap convention, full/empty detection and producer/consumer ownership. Verify boundary transitions, interrupt timing and the platform-supported synchronization or barrier mechanism with representative tests.