less spinlock/UB - #33
Conversation
📝 WalkthroughWalkthrough
ChangesStream Threading and State-Machine Fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
inc/mkn/gpu/stream.hpp (1)
321-330: ⚡ Quick winGood fix for spinlock behavior.
Setting
SFS::SKIPinstead ofSFS::FIRSTprevents immediate retry within the same scan, reducing contention.Note: There's a remaining data race between this write (outside
work_mutex) and reads inget_work()(inside mutex). The ownership model provides practical safety since only the "owning" thread (that set BUSY) modifies this slot, and other threads skip BUSY items. For full correctness,statuselements would need to be atomic, but that's a larger change for a follow-up.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@inc/mkn/gpu/stream.hpp` around lines 321 - 330, There is a data race between the write to strat.status[i] in the run method (outside the work_ mutex) and reads in get_work() (inside the mutex). To fix this, convert the status field or its elements to use atomic types such as std::atomic<SFS> to ensure thread-safe access to the status array across the work scheduling logic. This provides proper synchronization for reads and writes without relying on external locking.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@inc/mkn/gpu/stream.hpp`:
- Around line 321-330: There is a data race between the write to strat.status[i]
in the run method (outside the work_ mutex) and reads in get_work() (inside the
mutex). To fix this, convert the status field or its elements to use atomic
types such as std::atomic<SFS> to ensure thread-safe access to the status array
across the work scheduling logic. This provides proper synchronization for reads
and writes without relying on external locking.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 53e94561-7bc6-4677-afd6-ff42655595f1
📒 Files selected for processing (2)
inc/mkn/gpu/stream.hpptst/any/async_streaming.cpp
💤 Files with no reviewable changes (1)
- tst/any/async_streaming.cpp
Summary by CodeRabbit
Bug Fixes
Refactor