kmc-solid: Synchronize with the read when sending a joining task ID to a joinee

This commit is contained in:
Tomoaki Kawada 2022-12-12 13:44:06 +09:00
parent 304c6dcaed
commit 6fbef06f26

View file

@ -151,6 +151,9 @@ pub unsafe fn new(stack: usize, p: Box<dyn FnOnce()>) -> io::Result<Thread> {
// Since the parent might drop `*inner` and terminate us as
// soon as it sees `JOIN_FINALIZE`, the release ordering
// must be used in the above `swap` call.
//
// To make the task referred to by `parent_tid` visible, we
// must use the acquire ordering in the above `swap` call.
// [JOINING → JOIN_FINALIZE]
// Wake up the parent task.
@ -218,11 +221,15 @@ pub fn join(self) {
let current_task = current_task as usize;
match inner.lifecycle.swap(current_task, Ordering::Acquire) {
match inner.lifecycle.swap(current_task, Ordering::AcqRel) {
LIFECYCLE_INIT => {
// [INIT → JOINING]
// The child task will transition the state to `JOIN_FINALIZE`
// and wake us up.
//
// To make the task referred to by `current_task` visible from
// the child task's point of view, we must use the release
// ordering in the above `swap` call.
loop {
expect_success_aborting(unsafe { abi::slp_tsk() }, &"slp_tsk");
// To synchronize with the child task's memory accesses to