Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RwLock and std::box - parking_lot does not allocate ? #285

Open
luke-titley opened this issue May 21, 2021 · 1 comment
Open

RwLock and std::box - parking_lot does not allocate ? #285

luke-titley opened this issue May 21, 2021 · 1 comment

Comments

@luke-titley
Copy link

Hey,
So i've been reading through the docs/notes and parking_lot sounds awesome. I'm using std RwLock a lot and I was surprised to learn a few months back that because pthread primitives are non TM that rust std lib has to box them. You mention in the notes that parking_lot RwLock is just one additional word of space. I just want to clarify, does this means a parking_lot RwLock doesn't not implicitly allocate?

@bjorn3
Copy link
Contributor

bjorn3 commented May 21, 2021

Correct. parking_lot only needs a single AtomicUsize as state next to the actual value. This AtomicUsize can be moved together with the rest of the RwLock and as such doesn't need to be boxed.

/// Raw reader-writer lock type backed by the parking lot.
pub struct RawRwLock {
state: AtomicUsize,
}

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

No branches or pull requests

2 participants