Skip to content

Conversation

@wang384670111
Copy link

We still need Release here to make sure our write of lines and nlines happens before this, and we don't need Acquire here since there are no modifications we need to make visible to other thread.

pb/src/multi.rs

Lines 160 to 163 in d60b964

state.lines.push(String::new());
state.nlines += 1;
self.nbars.fetch_add(1, Ordering::SeqCst);

The load at 210 should use Acquire to synchronize with the store of lines and nlines, which are read at 220 and 224. The CAS operation at 214 can be Relaxed since, at this point, the message has done its job. Thus, this operation does not provide synchronization, only atomicity.

pb/src/multi.rs

Lines 210 to 234 in d60b964

while self.nbars.load(Ordering::SeqCst) > 0 {
// receive message
let msg = self.chan.1.recv().unwrap();
if msg.done {
self.nbars.fetch_sub(1, Ordering::SeqCst);
continue;
}
out.clear();
let mut state = self.state.lock().unwrap();
state.lines[msg.level] = msg.string;
// and draw
if !first {
out += &move_cursor_up(state.nlines);
} else {
first = false;
}
for l in state.lines.iter() {
out.push_str(&format!("\r{}\n", l));
}
printfl!(state.handle, "{}", out);
}

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.

1 participant