Threads

Ken Brown kbrown@cornell.edu
Mon Oct 20 13:04:00 GMT 2014


When trying to debug emacs in gdb, I see several threads, but it's not always 
clear who created those threads and what they're doing.  As an example, I 
attached gdb to an emacs-X11 process (running under X) shortly after starting 
it, and I obtained the backtrace appended at the end of this message.

I assume Thread 12 was created by gdb.  Thread 6 appears to be a timer thread 
and Thread 2 appears to be a signal thread; I assume both of these were created 
by the Cygwin DLL.  And Thread 1 is the main thread.  I don't have any idea 
where the other threads came from.  Presumably at least one of them was created 
by Glib.

The situation is similar with emacs-w32 and emacs-nox, but with fewer threads.

In general, is there a way I can understand where all the threads come from?  My 
reason for asking is that we're still getting emacs bug reports on 64-bit 
Cygwin, with random crashes or assertion violations that are "impossible" 
according to the gdb backtraces. [*]  So I'm wondering whether they're caused by 
interference from other threads.

Or is there some other plausible explanation for "impossible" crashes?  This 
can't just be a result of a gdb bug, because in at least one case the assertion 
can be shown to be valid by using printf instead of gdb.

Ken

[*] By "impossible" I mean that examination of the relevant variables in gdb 
shows that the assertions are in fact true.  Two ongoing examples are

    http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18438
    http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18769


=============thread apply all bt==============================

Thread 12 (Thread 6288.0x554):
#0  0x0000000077b50591 in ntdll!DbgBreakPoint ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x0000000077bf7f48 in ntdll!DbgUiRemoteBreakin ()
     at /c/Windows/SYSTEM32/ntdll.dll
#2  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#3  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#4  0x0000000000000000 in  ()

Thread 11 (Thread 6288.0x2280):
#0  0x0000000077b52bba in ntdll!ZwWaitForWorkViaWorkerFactory ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x0000000077b1fe3b in ntdll!RtlValidateHeap ()
     at /c/Windows/SYSTEM32/ntdll.dll
#2  0x000000018004619b in _cygtls::call2(unsigned int (*)(void*, void*), void*, 
void*) (this=0x2000002, func=0x0, arg=0x5e82d0, buf=buf@entry=0x47bcd50)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:100
#3  0x00000001800462f4 in _cygtls::call(unsigned int (*)(void*, void*), void*) 
(func=<optimized out>, arg=<optimized out>)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:30
#4  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#5  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#6  0x0000000000000000 in  ()

Thread 10 (Thread 6288.0x22c0):
#0  0x0000000077b52bba in ntdll!ZwWaitForWorkViaWorkerFactory ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x0000000077b1fe3b in ntdll!RtlValidateHeap ()
     at /c/Windows/SYSTEM32/ntdll.dll
#2  0x000000018004619b in _cygtls::call2(unsigned int (*)(void*, void*), void*, 
void*) (this=0x2000002, func=0x29000029, arg=0x5e82d0, buf=buf@entry=0x4bbcd50)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:100
#3  0x00000001800462f4 in _cygtls::call(unsigned int (*)(void*, void*), void*) 
(func=<optimized out>, arg=<optimized out>)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:30
#4  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#5  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#6  0x0000000000000000 in  ()

Thread 9 (Thread 6288.0x1e98):
#0  0x0000000077b515fa in ntdll!ZwDelayExecution ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda11203 in SleepEx () at /c/Windows/system32/KERNELBASE.dll
#2  0x000000018010d970 in thread_pipe(void*) (arg=0x600d2bfe0)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/select.cc:690
#3  0x0000000180044fc5 in cygthread::callfunc(bool) (this=this@entry=0x1801d0500 
<threads+352>, issimplestub=issimplestub@entry=false)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:51
#4  0x000000018004552a in cygthread::stub(void*) (arg=arg@entry=0x1801d0500 
<threads+352>) at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:93
#5  0x000000018004619b in _cygtls::call2(unsigned int (*)(void*, void*), void*, 
void*) (this=0x43bce00, func=
     0x1800454d0 <cygthread::stub(void*)>, arg=0x1801d0500 <threads+352>, 
buf=buf@entry=0x43bcd50) at 
/usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:100
#6  0x00000001800462f4 in _cygtls::call(unsigned int (*)(void*, void*), void*) 
(func=<optimized out>, arg=<optimized out>)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:30
#7  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#8  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#9  0x0000000000000000 in  ()

Thread 8 (Thread 6288.0x1ae4):
#0  0x0000000077b5186a in ntdll!ZwWaitForMultipleObjects ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda11430 in KERNELBASE!GetCurrentProcess ()
     at /c/Windows/system32/KERNELBASE.dll
#2  0x0000000000000000 in  ()

Thread 7 (Thread 6288.0x1bac):
#0  0x0000000077b5134a in ntdll!ZwRemoveIoCompletion ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefd095941 in  () at /c/Windows/System32/mswsock.dll
#2  0x0000000000000000 in  ()

Thread 6 (Thread 6288.0xf40):
#0  0x0000000077b512fa in ntdll!ZwWaitForSingleObject ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda110dc in WaitForSingleObjectEx ()
     at /c/Windows/system32/KERNELBASE.dll
#2  0x000000018013db94 in timer_thread(void*) (x=0x37ba9d8)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/timer.cc:145
#3  0x0000000180044fc5 in cygthread::callfunc(bool) (this=this@entry=0x1801d0450 
<threads+176>, issimplestub=issimplestub@entry=false)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:51
#4  0x000000018004552a in cygthread::stub(void*) (arg=arg@entry=0x1801d0450 
<threads+176>) at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:93
#5  0x000000018004619b in _cygtls::call2(unsigned int (*)(void*, void*), void*, 
void*) (this=0x37bce00, func=
     0x1800454d0 <cygthread::stub(void*)>, arg=0x1801d0450 <threads+176>, 
buf=buf@entry=0x37bcd50) at 
/usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:100
#6  0x00000001800462f4 in _cygtls::call(unsigned int (*)(void*, void*), void*) 
(func=<optimized out>, arg=<optimized out>)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:30
#7  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#8  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#9  0x0000000000000000 in  ()

Thread 5 (Thread 6288.0x1cc0):
#0  0x0000000077b515fa in ntdll!ZwDelayExecution ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda11203 in SleepEx () at /c/Windows/system32/KERNELBASE.dll
#2  0x000000018010d970 in thread_pipe(void*) (arg=0x600045f20)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/select.cc:690
#3  0x0000000180044fc5 in cygthread::callfunc(bool) (this=this@entry=0x1801d03f8 
<threads+88>, issimplestub=issimplestub@entry=false)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:51
#4  0x000000018004552a in cygthread::stub(void*) (arg=arg@entry=0x1801d03f8 
<threads+88>) at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:93
#5  0x000000018004619b in _cygtls::call2(unsigned int (*)(void*, void*), void*, 
void*) (this=0x33bce00, func=
     0x1800454d0 <cygthread::stub(void*)>, arg=0x1801d03f8 <threads+88>, 
buf=buf@entry=0x33bcd50) at 
/usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:100
#6  0x00000001800462f4 in _cygtls::call(unsigned int (*)(void*, void*), void*) 
(func=<optimized out>, arg=<optimized out>)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:30
#7  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#8  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#9  0x0000000000000000 in  ()

Thread 4 (Thread 6288.0x620):
#0  0x0000000077b5186a in ntdll!ZwWaitForMultipleObjects ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda11430 in KERNELBASE!GetCurrentProcess ()
     at /c/Windows/system32/KERNELBASE.dll
#2  0x0000000000000000 in  ()

Thread 3 (Thread 6288.0x50c):
#0  0x0000000077b5186a in ntdll!ZwWaitForMultipleObjects ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x0000000077b1b037 in ntdll!TpIsTimerSet () at /c/Windows/SYSTEM32/ntdll.dll
#2  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#3  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#4  0x0000000000000000 in  ()

Thread 2 (Thread 6288.0x4ec):
#0  0x0000000077b5131a in ntdll!ZwReadFile () at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda11a7a in ReadFile () at /c/Windows/system32/KERNELBASE.dll
#2  0x00000000779f0a19 in ReadFile () at /c/Windows/system32/kernel32.dll
#3  0x00000001801197c2 in wait_sig(void*) ()
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/sigproc.cc:1239
#4  0x0000000180044fc5 in cygthread::callfunc(bool) (this=this@entry=0x1801d03a0 
<threads>, issimplestub=issimplestub@entry=false)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:51
#5  0x000000018004552a in cygthread::stub(void*) (arg=arg@entry=0x1801d03a0 
<threads>) at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygthread.cc:93
#6  0x000000018004619b in _cygtls::call2(unsigned int (*)(void*, void*), void*, 
void*) (this=0x23ace00, func=
     0x1800454d0 <cygthread::stub(void*)>, arg=0x1801d03a0 <threads>, 
buf=buf@entry=0x23acd50) at 
/usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:100
#7  0x00000001800462f4 in _cygtls::call(unsigned int (*)(void*, void*), void*) 
(func=<optimized out>, arg=<optimized out>)
     at /usr/src/debug/cygwin-1.7.32-1/winsup/cygwin/cygtls.cc:30
#8  0x00000000779f59ed in KERNEL32!BaseThreadInitThunk ()
     at /c/Windows/system32/kernel32.dll
#9  0x0000000077b2c541 in ntdll!RtlUserThreadStart ()
     at /c/Windows/SYSTEM32/ntdll.dll
#10 0x0000000000000000 in  ()

Thread 1 (Thread 6288.0x2304):
#0  0x0000000077b5186a in ntdll!ZwWaitForMultipleObjects ()
     at /c/Windows/SYSTEM32/ntdll.dll
#1  0x000007fefda11430 in KERNELBASE!GetCurrentProcess ()
     at /c/Windows/system32/KERNELBASE.dll
#2  0x0000000000000001 in  ()
Continuing.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list