diff --git a/embassy-executor/src/raw/mod.rs b/embassy-executor/src/raw/mod.rs index 0113510d..b47b90fb 100644 --- a/embassy-executor/src/raw/mod.rs +++ b/embassy-executor/src/raw/mod.rs @@ -199,12 +199,7 @@ impl AvailableTask { pub fn claim(task: &'static TaskStorage) -> Option { task.raw .state - .compare_exchange( - STATE_ELIGIBLE, - STATE_SPAWNED | STATE_RUN_QUEUED, - Ordering::AcqRel, - Ordering::Acquire, - ) + .compare_exchange(STATE_ELIGIBLE, STATE_CLAIMED, Ordering::AcqRel, Ordering::Acquire) .ok() .map(|_| Self { task }) } @@ -214,6 +209,11 @@ impl AvailableTask { self.task.raw.poll_fn.set(Some(TaskStorage::::poll)); self.task.future.write_in_place(future); + self.task + .raw + .state + .store(STATE_SPAWNED | STATE_RUN_QUEUED, Ordering::Release); + let task = TaskRef::new(self.task); SpawnToken::new(task)