logoalt Hacker News

nextaccounticyesterday at 5:31 PM3 repliesview on HN

How can a parking_lot lock be less than 1 byte? does this uses unsafe?

Rust in general doesn't support bit-level objects unless you cast things to [u8] and do some shifts and masking manually (that is, like C), which of course is wildly unsafe for data structures with safety invariants


Replies

pizlonatoryesterday at 7:20 PM

Original post: https://webkit.org/blog/6161/locking-in-webkit/

Post that mentions the two bit lock: https://webkit.org/blog/7122/introducing-riptide-webkits-ret...

I don’t know the details of the Rust port but I don’t imagine the part that involves the two bits to require unsafe, other than in the ways that any locking algorithm dances with unsafety in Rust (ownership relies on locking algorithms being correct)

show 1 reply
bobbylarrybobbyyesterday at 10:37 PM

The lock uses two bits but still takes up a whole (atomic) byte

Conscatyesterday at 5:44 PM

This article elaborates how it works.

show 1 reply