Skip to content

RSDK-13439 remove std::memory_order usages#28

Merged
oliviamiller merged 1 commit intoviam-modules:mainfrom
oliviamiller:remove-mem-ordering
Mar 4, 2026
Merged

RSDK-13439 remove std::memory_order usages#28
oliviamiller merged 1 commit intoviam-modules:mainfrom
oliviamiller:remove-mem-ordering

Conversation

@oliviamiller
Copy link
Collaborator

@oliviamiller oliviamiller commented Feb 25, 2026

The explicit memory_order_relaxed and memory_order_release/acquire usages added unnecessary complexity without benefit. memory_order_relaxed leaves the CPU and compiler free to reorder the operations, making correctness dependent on the non-obvious happens-before chain through the release on total_samples_written counter. The default memory_order_seq_cst already performs acquire on loads and release on stores, making the explicit arguments redundant.

Switching to using the default memory ordering everywhere to make the code easier to reason about.

ty @dgottlieb for pointing this out to me

1 approval needed.

@oliviamiller oliviamiller changed the title rm memory ordering RSDK-13439 remove std::memory_order usages Mar 3, 2026
@oliviamiller oliviamiller marked this pull request as ready for review March 3, 2026 15:33
Copy link

@seanavery seanavery left a comment

Choose a reason for hiding this comment

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

Thanks for the explainer!

So there is no perf tradeoff swapping the relaxed loads in the read_samples loop for seq_cst?

Copy link

@hexbabe hexbabe left a comment

Choose a reason for hiding this comment

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

[optional] performance profiling to get an idea of how performant this opt is

@oliviamiller
Copy link
Collaborator Author

Thanks for the explainer!

So there is no perf tradeoff swapping the relaxed loads in the read_samples loop for seq_cst?

as long as the samples are read before the next portaudio callback theres no performance difference, the overhead from seq_cst is negligible.

@oliviamiller oliviamiller merged commit bfc084a into viam-modules:main Mar 4, 2026
5 checks passed
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