4 ms·
It looked simple enough, but I was curious about the threading example on https://github.com/joewalnes/websocketd/wiki/CPP-Input-Output-Example https://github.c
by FullyFunctional 8y ago
It looked simple enough, but I was curious about the threading example on https://github.com/joewalnes/websocketd/wiki/CPP-Input-Output-Example https://github.com/joewalnes/websocketd/wiki/CPP-Input-Outpu...
The variable `count` appears to be incremented non-atomically from two different threads. Is that safe in C++?
- deleted 8y ago[deleted]
- comex 8y agoIt is unsafe. But it would be safe if these two lines were swapped: count++; pthread_mutex_lock(&m); since the reader already holds the mutex while reading `count`.
- justinclift 8y agoDo a PR or equivalent?
- saagarjha 8y agoFriendly reminder that not everyone is in a position where they can create pull requests against random projects: they might not have time, or clearance from their company's legal department, or…
- justinclift 8y ago??? Note it was a question. As you mention, not everyone can do so (etc).
- saagarjha 8y agoThe question looked like "why are aren't you making a PR for this".
- slavik81 8y agoThe second example is also leaking memory.