Skip to content

sys/tsrb is not thread safe #9882

@jcarrano

Description

@jcarrano

Description

The "Thread-safe ringbuffer" is not actually thread safe.

Thread safety in this module depends upon reads and writes to unsigned int being atomic. C99 makes no guarantees with respect to atomicity (and they are probably NOT atomic in 8-bit platforms).

To fix this, access to these variables should be wrapped in a save interrupt mask/restore interrupt mask block. Alternatively, for architectures that support it, an asm statement can be used to ensure a single-cycle uninterruptible operation.

Steps to reproduce the issue

  1. Grab a copy of the C99 standard.
  2. Verify that the safety of reads and writes in the presence of interrupts/signals is unspecified.

Metadata

Metadata

Assignees

Labels

Type: bugThe issue reports a bug / The PR fixes a bug (including spelling errors)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions