<div dir="ltr">That might work, on Windows I think we could identify this by looking for ntdll.dll!TppWorkerThread() in the stack frame.  This might not be exactly the same across OS versions, but we could handle all cases as new ones are discovered.<div><br></div><div>We would have to make sure that all developers are educated on the distinction, so that only user threads are queried in future tests, but it has the advantage of not needing any modifications to the inferior</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 2, 2015 at 1:06 PM Greg Clayton <<a href="mailto:gclayton@apple.com">gclayton@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">One idea is add the ability to discover which of any of the current threads are or are not user created. This might help us.<br>
<br>
On MacOSX, the main thread would always be considered user created, and any other thread, it is quite easy to tell. User created threads could be ones whose bottom stack frame is "thread_start"<br>
<br>
    ....<br>
    frame #8: 0x00007fff9b47c41d libsystem_pthread.dylib thread_start + 13<br>
<br>
Where OS created threads have their last frames in "start_wqthread" or "_dispatch_mgr_thread":<br>
<br>
    ...<br>
    frame #2: 0x00007fff9b47c40d libsystem_pthread.dylib start_wqthread + 13<br>
<br>
or:<br>
<br>
    ...<br>
    frame #2: 0x00007fff9c298a6a libdispatch.dylib _dispatch_mgr_thread + 52<br>
<br>
<br>
So it might be easy to add API to SBThread like:<br>
<br>
bool<br>
SBThread::IsUserCreated();<br>
<br>
Then we could teach the tests to filter out any threads that are not user created?<br>
<br>
Greg<br>
<br>
<br>
> On Sep 2, 2015, at 12:31 PM, Zachary Turner via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a>> wrote:<br>
><br>
> 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.<br>
><br>
> 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.<br>
><br>
> 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).<br>
><br>
> So I need to find a way to write these tests portably.<br>
><br>
> Do all platforms have a way to assign a thread a name?  Looking in Host/*/ThisThread.cpp, it seems:<br>
><br>
> 1) Linux and MacOSX inferiors can use pthread_setname_np<br>
> 2) FreeBSD inferiors can use pthread_set_name_np<br>
> 3) Windows inferiors can raise a magic exception which the debugger is expected to recognize<br>
><br>
> 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.<br>
><br>
> Does anyone have any thoughts on this or other possible approaches?<br>
><br>
> 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.<br>
> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org" target="_blank">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div>