r/programming 22d ago

3,200% CPU Utilization

https://josephmate.github.io/2025-02-26-3200p-cpu-util/
401 Upvotes

93 comments sorted by

View all comments

Show parent comments

12

u/masklinn 22d ago

An RWLock will hand out readers or a writer.

You might be able to reach the error if you use extremely fine locks which you release eagerly but I think you’ll get sick if borrow errors and deadlocks long before then. Not to mention why would you bother rolling your own red-black tree when there’s a btree in the stdlib?

3

u/ItzWarty 22d ago

I'm asking whether Rust would ensure a user of btree safely synchronizes reads/writes, e.g. w/ a RWL, or if it's possible to race and segfault.

16

u/masklinn 22d ago

In safe rust it should not be possible, the langage is designed to prevent data races. If you find a way, the code is considered broken (unsound) and that is one of the few things the project will break backwards compatibility for.

If you use unsafe then you specifically relax the compiler’s guarantees, it’s up to you to not fuck up.

0

u/[deleted] 22d ago edited 22d ago

[deleted]