Menu

#674 Race condition in winpthread

v1.0 (example)
open
nobody
None
5
2017-09-28
2017-09-28
No

There seems to be a race condition somwhere when using C++11 thread's detach function. Here is a minimal example. It is a program that launches an std::thread that waits for an atomic int to be incremented, then counts up to a certain number (just to spend some time) and calls detach on the created std::thread. It repeats this ten thousands times adjusting at every iteration the count in such a way to create a race condition between the thread's callback end and the call to the detach method (which is, anyway, perfectly legal C++). Compiling this program with gcc 7.1.1 (archlinux build) and mingw 5.0.2 and running it under wine 2.17 or under Windows 10 (and passing to it some string as command line argument, which means that it doesn't print anything on stdout, slowing it down) it almost always gets locked, which should never happen.
The same program built with the same gcc version for linux always terminates correctly.

1 Attachments

Discussion


Log in to post a comment.