2 ms·
> constrained parallelism in Rust I'm... unsure what you mean. As far as I know Rust doesn't require any extra runtime overhead for parallelism that wouldn't b
by _bxg1 7y ago
> constrained parallelism in Rust
I'm... unsure what you mean. As far as I know Rust doesn't require any extra runtime overhead for parallelism that wouldn't be required in C++. Rust ensures you use locking mechanisms at compile time, but you still need those in C++, you just "have to be aware of it" in that case.
I suppose Rust does require a value shared across threads to be reference-counted, where that might technically be optional in C++. But then you get to do manual deallocations across threads, which just sounds like a nightmare. And each thread only has to increment the counter once, so the overhead should be minuscule compared to the overhead of creating a thread in the first place. The only exception would be if you have bad lock coordination, but again, that problem is no different in Rust than it is in C++.
- steveklabnik 7y ago> I suppose Rust does require a value shared across threads to be reference-counted It does not require it; that is one of many possible strategies, depending on what you're doing.
- _bxg1 7y agoWhat are the other strategies? Aside from making it static.
- cyphar 7y agoMuch like in C, you could use several other schemes such as a Mutex (or RwLock). There are crates which implement more complicated memory management primitives -- the most obvious example being crossbeam[1]. Crossbeam even has an implementation of an epoch-based memory manager[2] which (in very loose terms) amortises the cost of reference counting each object by tracking the epochs of each thread and freeing objects once all threads have moved past the "death time" of an object. [1]: https://docs.rs/crossbeam/ https://docs.rs/crossbeam/ [2]: https://docs.rs/crossbeam/0.7.3/crossbeam/epoch/index.html https://docs.rs/crossbeam/0.7.3/crossbeam/epoch/index.html
- _bxg1 7y agoNormal mutexes in Rust still have to be paired with a reference-counting structure. Those are separate mechanisms. I don't know anything about the epoch-based manager, but it does sound interesting.
- steveklabnik 7y agoAnything that you can do in any other language. Rust doesn't force you to do anything special, only prove that what you're doing has defined behavior. No tools are forbidden.