Skip to content

Replace Mutex with cordyceps::TransferStack for Epochs and make no_std compatible#145

Draft
ilslv wants to merge 2 commits intojonhoo:mainfrom
ilslv:feat/remove-mutex-and-no-std
Draft

Replace Mutex with cordyceps::TransferStack for Epochs and make no_std compatible#145
ilslv wants to merge 2 commits intojonhoo:mainfrom
ilslv:feat/remove-mutex-and-no-std

Conversation

@ilslv
Copy link
Copy Markdown

@ilslv ilslv commented Apr 27, 2026

Hi! I've recently saw a talk and was wondering what will it take to remove Mutex lock on ReadHandle initialisation and drop.

The simplest approach I could come boils down to the following idea: what if ReadHandles wouldn't bother themselves with removal of their Epochs from shared Epochs and would just drop the Arc. Then WriteHandle can check for ReadHandle liveliness with Arc::strong_count since every Arc has a strong count of 1 or 2. After that it became obvious that something like cordyceps::TransferStack can be used to semantically replace Epochs from "shared storage of Epochs that is accessed both by ReadHandles and WriteHandle" to "a kinda channel to let WriteHandle know about new ReadHandles".

I also made library no_std compatible as mentioned in #101.

I think more tests should be added before merging, but before investing more time I would love to here about approach in general and haven't I missed something.

Comment thread Cargo.toml Outdated

[dependencies]
slab = "0.4.1"
cordyceps = { version = "0.3" }
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cordyceps has a following note

This is a hobby project. I’m working on it in my spare time, for my own personal use. I’m very happy to share it with the broader Rust community, and contributions and bug reports are always welcome. However, please remember that I’m working on this library for fun, and if it stops being fun…well, you get the idea.

Anyway, feel free to use and enjoy this crate, and to contribute back as much as you want to!

But implementation looks very solid and embassy-executor uses it

Comment thread src/epochs.rs
Comment on lines +16 to +18
/// [`ReadHandle`]s don't clean up anything on [`drop`], so there is opportunity for an unbounded
/// memory growth in case [`WriteHandle`] does nothing and new [`ReadHandle`]s are created and
/// dropped.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say this is my main concern with the implementation. Would this be a dealbreaker?

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

❌ Patch coverage is 90.54054% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.6%. Comparing base (1b9b8f4) to head (42a5df7).

Files with missing lines Patch % Lines
src/aliasing.rs 60.0% 2 Missing ⚠️
src/read/factory.rs 0.0% 2 Missing ⚠️
src/write.rs 94.2% 2 Missing ⚠️
src/read.rs 80.0% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/epochs.rs 100.0% <100.0%> (ø)
src/lib.rs 84.2% <100.0%> (+5.6%) ⬆️
src/read/guard.rs 43.4% <ø> (ø)
src/read.rs 56.5% <80.0%> (-1.9%) ⬇️
src/aliasing.rs 27.2% <60.0%> (ø)
src/read/factory.rs 0.0% <0.0%> (ø)
src/write.rs 73.3% <94.2%> (+3.4%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

strategy:
matrix:
msrv: ["1.60.0"]
msrv: ["1.66.0"]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cordyceps declares MSRV at 1.61.0, but actually it's 1.66.0. I'll report it to upstream a little later

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