(Mirror) cli : Use acquire/release semantics for stopping logic#101
(Mirror) cli : Use acquire/release semantics for stopping logic#101ngxson wants to merge 2 commits intongxson:masterfrom
Conversation
Previously, seq_cst ordering was enforced, which is slower and has no benefits when using only one atomic variable.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughSignal handling and interrupt state were refactored to use explicit atomic memory ordering and exchange semantics; the streaming generation loop condition was simplified; the stop flag is reset via a new reset function; Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI as CLI Process
participant Signal as OS Signal
participant Gen as Generator Loop
User->>CLI: Start generation
CLI->>Gen: begin streaming generation
Signal->>CLI: SIGINT/Ctrl+C
CLI->>CLI: g_is_interrupted.exchange(true, memory_order_acq_rel)
CLI->>Gen: should_stop()? (load memory_order_acquire)
alt stop requested
Gen->>CLI: stop loop (exit generation)
CLI->>CLI: reset_stop() (store memory_order_release)
else continue
Gen->>Gen: continue streaming
end
CLI->>User: exit/cleanup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tools/cli/cli.cpp`:
- Around line 46-53: The second-interrupt handler uses non-async-signal-safe
functions (fprintf, fflush, std::exit); change it to only call async-signal-safe
primitives: use g_is_interrupted.exchange as-is, then write(2) to STDOUT_FILENO
(or use a literal escape sequence buffer) to clear colors, and call _exit(130)
instead of std::exit; update the block that currently references
g_is_interrupted and the fprintf/fflush/std::exit sequence to use write(...) and
_exit(...) so the signal handler is POSIX async-signal-safe.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
@coderabbitai use mirror preset for review
mirror ggml-org#21822
Summary by CodeRabbit
Bug Fixes
Performance
Other