3 ms·
I think the key difference here is that in your code you’re saying you “know” that it’s safe to write to these certain sections of the array from different thre
by pixel_fcker 7y ago
I think the key difference here is that in your code you’re saying you “know” that it’s safe to write to these certain sections of the array from different threads. That’s an invariant that‘s held in your memory (or in a comment maybe).
The rust equivalent is doing the exact same thing but requires you to formalise that invariant in your code by using one of the methods defined above.
I can see how initially this looks like an extra hoop to jump through but after using it for a while I’ve found the opposite is true: because those invariants are checked by the compiler it’s one less thing I have to keep in my head and I can concentrate on the real problem.
- safercplusplus 7y agoAnd also one less thing to transfer to the heads of anyone else that might need/want to understand the code. (Often the author him or herself at some point in the future, right?) Though equivalent facilities are available in C++ [1][2] (and can now/soon be enforced[3]). [1] https://github.com/duneroadrunner/SaferCPlusPlus/blob/master/README.md#tasyncrasectionsplitter https://github.com/duneroadrunner/SaferCPlusPlus/blob/master... [2] https://github.com/duneroadrunner/SaferCPlusPlus/blob/master/README.md#scope-threads https://github.com/duneroadrunner/SaferCPlusPlus/blob/master... [3] https://github.com/duneroadrunner/scpptool https://github.com/duneroadrunner/scpptool