Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic variable: Relaxed memory ordering #11

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,14 @@ impl Cli {
"Potential deadlock detected, too long without output from child process"
)),
MainMessage::ChildExited(exit_status) => {
// Memory ordering comment: We use relaxed since
// there is only one atomic variable and we are
// not trying to establish any cross thread
// happens before relationship. Total modification
// order is guaranteed in the individual atomic
// variable.
if self.can_exit && exit_status.success()
|| child_was_killed.load(Ordering::SeqCst)
|| child_was_killed.load(Ordering::Relaxed)
{
eprintln!("Child exited, treating as a success case");
Ok(())
Expand Down Expand Up @@ -326,7 +332,13 @@ fn handle_signals(
.with_context(|| format!("Unable to convert signal value for nix: {signal}"))
{
Ok(signal) => {
child_was_killed.store(true, Ordering::SeqCst);
// Memory ordering comment: We use relaxed since there
// is only one atomic variable and we are not trying
// to establish any cross thread happens before
// relationship. Total modification
// order is guaranteed in the individual atomic
// variable.
child_was_killed.store(true, Ordering::Relaxed);
if let Err(e) = nix::sys::signal::kill(child_pid, signal)
.context("Unable to send signal to child process")
{
Expand Down
Loading