deadlock on console mutex in gdb
Takashi Yano
takashi.yano@nifty.ne.jp
Thu Dec 23 09:24:40 GMT 2021
On Wed, 22 Dec 2021 18:17:20 -0400
David McFarland wrote:
> ===== test.c
> #include <pthread.h>
> #include <stdio.h>
>
> void *thread(void* p) {
> printf("thread %p\n", p);
> return 0;
> }
>
> int main() {
> pthread_t ids[100];
> for (int i = 0; i < 100; ++i) {
> pthread_create(&ids[i], 0, &thread, &ids[i]);
> }
> for (int i = 0; i < 100; ++i) {
> pthread_join(ids[i], 0);
> }
> return 0;
> }
> =====
>
> If I compile that with gcc and run it under gdb, it hangs almost
> immediately. 5/5 attempts using a fresh cygwin with latest packages.
Thanks for the test case. I could reproduce your problem.
I looked into this problem and found the mechanism causing
the issue.
GDB inferior may be suspended while the inferior grabs mutex.
When the inferior creates new thread, GDB receives
CREATE_THREAD_DEBUG_EVENT and inferior is suspended even if
the inferior is grabing the mutex. This causes deadlock in
terminal I/O.
I think there is no other way than not to wait mutex in the
debugger process. If anyone have any other idea, please let
me know.
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin-developers
mailing list