Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why didn't you use a Mutex?


What are you thinking?

I could have used a Mutex then cast the `&Mutex` to `&mut Mutex` so that I could call `.get_mut()`. But this didn't seem simpler.


I wanted to avoid unsafe.

Because unsafe introduces conceptual complications and it seemed to be simpler to avoid that in an example.


Well you can't have a memory race without unsafe. The goal of the example was to show undefined behaviour.


Ah, you wanted to show an example in Rust with unsafe where atomicity was not guaranteed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: