public inbox for cygwin-developers@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin-developers@cygwin.com
Cc: David McFarland <corngood@gmail.com>
Subject: Re: deadlock on console mutex in gdb
Date: Thu, 23 Dec 2021 18:24:40 +0900	[thread overview]
Message-ID: <20211223182440.e37115a4493516aca7ed7873@nifty.ne.jp> (raw)
In-Reply-To: <vrith7b0xp1r.fsf@gmail.com>

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>

  reply	other threads:[~2021-12-23  9:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-22 15:26 David McFarland
2021-12-22 20:44 ` Takashi Yano
2021-12-22 22:17   ` David McFarland
2021-12-23  9:24     ` Takashi Yano [this message]
2021-12-23 15:32       ` David McFarland
2021-12-23 19:28         ` David McFarland
2021-12-26 15:25           ` David McFarland
2022-01-13 11:09           ` Takashi Yano
2022-01-13 10:56         ` Takashi Yano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211223182440.e37115a4493516aca7ed7873@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=corngood@gmail.com \
    --cc=cygwin-developers@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).