meganz / mingw-std-threads

Standard threads implementation currently still missing on MinGW GCC on Windows
BSD 2-Clause "Simplified" License
439 stars 137 forks source link

Fix fatal bug: Threads must copy arguments. #59

Closed nmcclatchey closed 5 years ago

nmcclatchey commented 5 years ago

In #58 , @phma noticed an issue, in that threads which were passed an argument in a for loop were not properly disambiguated by it. I have replicated the behavior, and determined that it is caused by the thread constructor not properly copying its arguments. This is a fatal flaw, so it must be addressed immediately.

This pull request eliminates the problem using the following steps:

I recommend immediately updating this library. All projects that use this library should update their copy and recompile.

@alxvasilev , please merge this ASAP.

alxvasilev commented 5 years ago

Done, thanks!

phma commented 5 years ago

I verified that this bugfix fixes the bug in my program. I also found that if the main thread sleeps 10 ms after starting each thread, which I did so that the threads would get numbered in the order they're started as they add elements to threadStatus, each thread is passed the correct number before this bugfix, instead of being all passed 0 as with no delay.