Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- Handle the UNPARKING state correctly in `Receiver::drop()`.


## [0.1.10] - 2025-02-04
### Added
Expand Down
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,31 @@ impl<T> Drop for Receiver<T> {
// SAFETY: see safety comment at top of function
unsafe { dealloc(self.channel_ptr) };
}
// The sender has observed the RECEIVING state and is currently reading the waker from
// a poll. We need to loop here until we observe the MESSAGE or DISCONNECTED state.
// We busy loop here since we know the sender is done very soon.
#[cfg(any(feature = "std", feature = "async"))]
UNPARKING => loop {
hint::spin_loop();
// ORDERING: The load above has already synchronized with the write of the message.
match channel.state.load(Relaxed) {
MESSAGE => {
// SAFETY: we are in the message state so the message is initialized
unsafe { channel.drop_message() };

// SAFETY: see safety comment at top of function
unsafe { dealloc(self.channel_ptr) };
break;
}
DISCONNECTED => {
// SAFETY: see safety comment at top of function
unsafe { dealloc(self.channel_ptr) };
break;
}
UNPARKING => (),
_ => unreachable!(),
}
},
_ => unreachable!(),
}
}
Expand Down
Loading