3 ms·
You can also use a locked data structure in Rust. This was to show how to actually use mutexes. In theory (assuming a Python with GIL or locked dicts) you can
by the_mitsuhiko 11y ago
You can also use a locked data structure in Rust. This was to show how to actually use mutexes. In theory (assuming a Python with GIL or locked dicts) you can get rid of the mutex as well. But this only works for such a simple example in any case.
The mutex generally works and was meant to show the relationship of the borrow checker and the mutability system to the mutex that moves checks to runtime.
- aidos 11y agoOk cool, I figured that was the case. I mostly sat down to write out the example to humour myself during my lunch break (as I said, I don't do much with threads so wanted to make sure I understood what was going on). The ownership/borrowing system is really interesting, not something I'd seen before - though I guess other languages do it too?
- DasIch 11y agoOwnership/borrowing enforced at compile time doesn't exist in any other (practical) language. Though C++ has some runtime support for it and in C you would/should do it by convention.