embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.22k stars 718 forks source link

embassy-sync: Add RwLock #1394

Open PegasisForever opened 1 year ago

PegasisForever commented 1 year ago

Something like async-std's RwLock would be extremely helpful for implementing async programs.

PegasisForever commented 1 year ago

I think I can give this a shot, I already got a prototype working. Is there anyway I can write tests for asynchronous primitives running on embassy's executor? Or I just create a normal test which runs the rwlock using tokio?

Dirbaio commented 1 year ago

There's already some tests using futures-test: https://github.com/embassy-rs/embassy/blob/master/embassy-sync/src/channel.rs#L472

Using another executor is fine, embassy-sync is executor-independent and using embassy-executor would be annoying for tests because tasks are statically allocated.

PegasisForever commented 1 year ago

Didn't saw that, thanks!

elpiel commented 1 year ago

Awesome idea for a feature. I've wondered why there hasn't been anything like that so far.

Ragarnoy commented 1 year ago

How hard to implement would this be for a beginner?

PegasisForever commented 1 year ago

@Ragarnoy This is my current implementation so far: https://github.com/McMaster-Rocketry-Team/rust-monorepo/blob/master/vlfs/src/utils/rwlock.rs It works, however it is not fair, meaning too many readers can starve writers.