Skip to content

Lock the OBR mutex in head-tracking and limiter setters - #25

Merged
trsonic merged 1 commit into
mainfrom
fix/obr-head-rotation-data-race
Jul 31, 2026
Merged

Lock the OBR mutex in head-tracking and limiter setters#25
trsonic merged 1 commit into
mainfrom
fix/obr-head-rotation-data-race

Conversation

@trsonic

@trsonic trsonic commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

SetHeadRotation(), EnableHeadTracking() and EnableLimiter() wrote world_rotation_, head_tracking_enabled_ and limiter_enabled_ without acquiring mutex_, while Process() reads all three under the lock for the duration of each rendered block. Head rotation in particular is typically updated from a sensor thread while the audio thread renders, so the unsynchronized 4-float quaternion write could be observed torn mid-block — and all three writes are data races regardless.

Every other ObrImpl mutator already takes the mutex; this makes the remaining three do the same. The setters are only called from the C API wrappers (obr_capi.cpp), so no caller holds the lock and there is no deadlock path.

No functional change on a single thread; existing tests pass unchanged.

SetHeadRotation(), EnableHeadTracking() and EnableLimiter() wrote
world_rotation_, head_tracking_enabled_ and limiter_enabled_ without
acquiring mutex_, while Process() reads all three under the lock for
the duration of each rendered block. Head rotation in particular is
typically updated from a sensor thread while audio renders, so the
unsynchronized quaternion write could be observed torn mid-block, and
all three are data races regardless. Every other ObrImpl mutator
already takes the mutex; make these three do the same.
@trevorknight

Copy link
Copy Markdown
Contributor

Is OAR intended to support multithreading and be thread safe?

@trsonic

trsonic commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator Author

Is OAR intended to support multithreading and be thread safe?

I can only confirm that OBR is safe to be configured on one thread and render audio on another one. Hence this PR.

@yilun-zhangs

yilun-zhangs commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Is OAR intended to support multithreading and be thread safe?

Hi @trevorknight ,
Do you mean the different apis calling by different thread for one OAR handle,
or one thread per OAR handle?

@jingbo-marquis jingbo-marquis left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@trsonic
trsonic merged commit aae184e into main Jul 31, 2026
6 checks passed
@trsonic
trsonic deleted the fix/obr-head-rotation-data-race branch July 31, 2026 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants