Skip to content

feat: add RwSpinlock readers-writer lock - #18

Merged
phil-opp merged 1 commit into
rust-osdev:masterfrom
mkroening:rwlock
Oct 18, 2023
Merged

phil-opp merged 1 commit into
rust-osdev:masterfrom
mkroening:rwlock

Conversation

@mkroening

Copy link
Copy Markdown
Member

This adds the RwSpinlock implementation from hermit-sync, which has been derived from spin, but

  • with separation of UPGRADABLE and EXCLUSIVE,
  • with optional exponential backoff,
  • with impl RawRwLockRecursive.

Depends on #16 for the backoff feature.
Closes #15

@mkroening

Copy link
Copy Markdown
Member Author

Rebased on latest master. Would you like more elaborate documentation and examples for these new types?

@mkroening mkroening mentioned this pull request Oct 17, 2023
@phil-opp

Copy link
Copy Markdown
Member

Looks like this still uses the backoff feature instead of the Relax parameter.

@phil-opp phil-opp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks a lot!

Note that I'm not an expert atomic operations, so I'm not 100% certain that all the orderings etc are correct. They looked all reasonable to me, though, and I didn't notice any issues.

It would be great if we could apply some more tooling to catch potential issues at some point (in some future PR). For example, we could run the randomized lock/unlock tests under a data race detector.

Comment thread src/rw_spinlock.rs Resolved
Comment thread src/rw_spinlock.rs Resolved
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
@mkroening

mkroening commented Oct 17, 2023 •

Copy link
Copy Markdown
Member Author

Looks like this still uses the backoff feature instead of the Relax parameter.

Fixed. I forgot during rebase. 😅

It would be great if we could apply some more tooling to catch potential issues at some point (in some future PR). For example, we could run the randomized lock/unlock tests under a data race detector.

Good point. Did you have any specific tool in mind?

I took a look at loom once, but their atomics are not const-constructible, so that clashes with lock_api. We might work around that, but that is probably a larger effort.

@phil-opp

Copy link
Copy Markdown
Member

Thanks!

I took a look at loom once, but their atomics are not const-constructible, so that clashes with lock_api. We might work around that, but that is probably a larger effort.

Yeah, looks like loom will be difficult to use then. I found this related issue: tokio-rs/loom#170

As an alternative, we could try Miri or ThreadSanitizer, which provide less strong guarantees, but should be easier to set up.

@phil-opp phil-opp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick fixes!

@phil-opp
phil-opp merged commit 9d803fe into rust-osdev:master Oct 18, 2023
@mkroening
mkroening deleted the rwlock branch October 18, 2023 07:28
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.

Readers-writer lock

2 participants