<div dir="ltr">Historically the pattern for tests that need to test situations involving threads has been to write the tests using pthreads, and then a common pattern on the python side of the test is to assert that the actual number of threads equals the expected number of threads.<div><br></div><div>To deal with the pthread portability issue, I ported most of these tests over to std::threads, but there is still another issue with them.</div><div><br></div><div>On Windows we can't assume anything about the number of threads in a program.  For example, a single-threaded hello world program actually has 3 threads, 2 of which are reserved for use by the operating system.  And the fact that there's 2 is just arbitrary, that might not remain the same between compiler versions, operating system versions, etc.  And to make matters worse it might not even remain constant through the life of the program (the assumption just being that we cannot make any assumptions, since we don't control the threads).</div><div><br></div><div>So I need to find a way to write these tests portably.</div><div><br></div><div>Do all platforms have a way to assign a thread a name?  Looking in Host/*/ThisThread.cpp, it seems:</div><div><br></div><div>1) Linux and MacOSX inferiors can use pthread_setname_np</div><div>2) FreeBSD inferiors can use pthread_set_name_np<br></div><div>3) Windows inferiors can raise a magic exception which the debugger is expected to recognize</div><div><br></div><div>Based on this, it seems that one possible way to write these tests portably is to have the test inferiors assign names to the threads, and have the tests index the threads by name instead of by ordinal.</div><div><br></div><div>Does anyone have any thoughts on this or other possible approaches?</div><div><br></div><div>I really would like to avoid having different inferiors or different tests for all of this functionality, as it will be very easy to get out of sync.</div></div>