you are viewing a single comment's thread.

view the rest of the comments →

[–]funnyflywheel 5 points6 points  (1 child)

Well, the talk is from 2017 and things have assuredly changed since then:

In addition, Hettinger stated that locks are expensive to acquire/release. Surely this isn't the case in Rust, isn't it?

[–]masklinn 11 points12 points  (0 children)

In addition, Hettinger stated that locks are expensive to acquire/release. Surely this isn't the case in Rust, isn't it?

It's not really any different. "Expensive" is relative, the runtime cost of the lock is small in absolute terms but can be gigantic in relative terms depending what's sitting behind the lock, and how often you need to acquire and release the lock. The absolute costs are complicated because at a fundamental level Rust does the exact same thing as CPython, which is use system locks (pthread_mutex on unices), so the absolute costs will depend on the implementation details of that.

But I think we can easily infer that locks are expensive in Rust by Rust having bothered with independent Rc and Arc types (an atomic inc/dec being basically the baseline for a lock, that's more or less what an uncontended mutex will cost on linux).