Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

PSA: parking_lot -> fuchsia-sync

18 views
Skip to first unread message

Adam Perry

unread,
Jan 10, 2024, 2:48:07 PM1/10/24
to rust-...@fuchsia.dev
TLDR: going forward please use //src/lib/fuchsia-sync (docs) instead of parking_lot on both target and host.

We're moving away from parking_lot in our tree in favor of an API-compatible lock library called fuchsia-sync. The main reason is that it's not great to have sched_yield calls in a lock's contended spin and more background is available in the original bug and linked commit messages.

No immediate action is required on your part, as I've already migrated current users and the parking_lot target is no longer visible to most code in our tree. It is still what you get behind the scenes if you use fuchsia-sync in host code, and the library is still used by some of our 3p deps, but I'm pruning that list and we have follow-up work identified to fully remove it from target-side code.

Let me know if you have any questions, and happy hacking in the new year!

--
Adam Perry

Yifei Teng

unread,
Jan 10, 2024, 3:26:38 PM1/10/24
to Adam Perry, rust-...@fuchsia.dev
Thanks for this improvement!!

I had a question, what is the policy for std::sync::Mutex? Is it better or worse or equivalent to one of the others?

--
All posts must follow the Fuchsia Code of Conduct https://fuchsia.dev/fuchsia-src/CODE_OF_CONDUCT or may be removed.
---
You received this message because you are subscribed to the Google Groups "rust-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rust-users+...@fuchsia.dev.
To view this discussion on the web visit https://groups.google.com/a/fuchsia.dev/d/msgid/rust-users/CA%2BvriKfwoDLrM2tc4inO%3Dz%3DPnsSzPwAWjZO%3DaNuy-U4by9gQEg%40mail.gmail.com.

Adam Perry

unread,
Jan 10, 2024, 4:03:44 PM1/10/24
to Yifei Teng, rust-...@fuchsia.dev
std::sync::Mutex is fine AFAIK, and currently uses an implementation which is pretty similar to fuchsia-sync although it supports lock poisoning. That said its API is not as ergonomic as fuchsia-sync, since you always need to unwrap the returned Result. And on Fuchsia we almost always build with panic=abort, making lock poisoning dead code. The runtime and compile-time overhead should be zero or minimal, but you get a bit noisier syntax when using std's locks.
--
Adam Perry

Tyler Mandry

unread,
Jan 10, 2024, 6:21:38 PM1/10/24
to Adam Perry, Yifei Teng, rust-...@fuchsia.dev
Locks in std are at least one byte bigger, and their unwrap calls may not be optimized away. At one point I put up an upstream pull request fixing this, but it has since languished and could use some dedicated attention.

Adam Perry

unread,
Jan 10, 2024, 6:31:13 PM1/10/24
to Tyler Mandry, Yifei Teng, rust-...@fuchsia.dev
Ah that's a good point about the size difference, I forgot that std wraps the inner mutex impl with the poison flag. And since our inner mutex type is 4 bytes with 4 byte alignment I think the size difference could be as much as double depending on the generic type layout involved.



--
Adam Perry
Reply all
Reply to author
Forward
0 new messages