﻿# Zephyr sensor FIFOs: enqueueing an item does not copy its sample

Keep intrusive FIFO membership and sensor-buffer ownership explicit. Reusing a queued item can corrupt the handoff even when its address and inference tensor shape look correct.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/edge-zephyr-sensor-fifo-item-membership/
Language: en

## A queued address refers to changing sensor data

A sensor producer fills an item, places it on a Zephyr FIFO and immediately fills the same object for the next capture. The inference thread later receives unexpected values even though its tensor shape is correct. The FIFO operation did not create an immutable sample snapshot. Identify whether the producer reused a queued node, overwrote a payload still owned by the consumer or passed a pointer to another mutable buffer. These defects require an ownership repair before evaluating model accuracy.

## FIFO items participate in the queue structure

The [Zephyr FIFO documentation](https://docs.zephyrproject.org/latest/kernel/services/data_passing/fifos.html) reserves pointer-sized linkage storage in ordinary FIFO items and requires appropriate alignment. It explicitly restricts an item to a single active instance across FIFO queues until removed. Re-adding the same queued item violates that contract. A payload-only structure cannot be treated as an intrusive node without the required layout. The allocation-assisted insertion alternative has another resource contract; it does not turn an arbitrary sample into a deep immutable copy.

## Copied messages have a different boundary

The [message-queue documentation](https://docs.zephyrproject.org/latest/kernel/services/data_passing/message_queues.html) describes fixed-size messages copied into a waiting receiver or queue storage. That can preserve bytes contained directly in the message. If those bytes are only a pointer, however, the referenced sensor payload remains elsewhere with its own lifetime. Choose the mechanism according to required sample ownership, item size and bounded resources. Do not infer a deep copy from the word message or assume a FIFO’s intrusive behavior matches a copied queue entry.

## Return ownership after consumption

Define a finite pool of distinct sample items or a deliberate copy boundary. The producer acquires a free item, completes a sample and transfers it; the consumer releases it only after its final required read. Removal from the FIFO ends queue membership, but does not necessarily mean inference has finished consuming the payload. Keep those events separate. When the pool is exhausted, the application needs an explicit overrun policy rather than quietly mutating an item already in use or claiming unlimited queue capacity.

## Propose a deliberately slow consumer fixture

Use harmless captures with recognizable distinct content and delay the consumer while the producer completes further samples. Observe item identity, membership transitions, payload contents and release events. Check that no object is simultaneously queued twice and that the producer cannot reacquire a still-consumed item. Compare a copied-message variant only under its actual payload representation. Acceptance requires source-consistent samples or explicit overruns. No RTOS thread or sensor ran here; the fixture defines a handoff check rather than measured throughput.

## Keep queue structure separate from model correctness

[Device-buffer lifetime](/journal/fg2-onnxruntime-io-binding-device-buffer-lifetime/) explains why an address alone is insufficient evidence. [Embedded pipeline measurement](/journal/unpu-bench-initialization-io-frequency-normalization-energy-sampling/) explains why acquisition and movement belong in system evaluation. Zephyr FIFO membership adds a specific structural requirement before those model measurements. Record the item layout, copy policy and final release boundary so an apparently unstable classifier is not blamed for receiving a changing or illegally queued sample.
