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

It looked simple enough, but I was curious about the threading example on 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++?



It 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`.


Do a PR or equivalent?


Friendly 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…


???

Note it was a question. As you mention, not everyone can do so (etc).


The question looked like "why are aren't you making a PR for this".


The second example is also leaking memory.




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

Search: