From: Eli Zaretskii <eliz@gnu.org>
To: Pedro Alves <palves@redhat.com>
Cc: tom@tromey.com, gdb-patches@sourceware.org
Subject: Re: [PATCH] Readline: Cleanup some warnings
Date: Wed, 20 Mar 2019 18:01:00 -0000 [thread overview]
Message-ID: <83mulps9vn.fsf@gnu.org> (raw)
In-Reply-To: <5751c371-3313-fc24-e4d7-83214eb99d0b@redhat.com> (message from Pedro Alves on Wed, 20 Mar 2019 17:50:36 +0000)
> Cc: tom@tromey.com, gdb-patches@sourceware.org
> From: Pedro Alves <palves@redhat.com>
> Date: Wed, 20 Mar 2019 17:50:36 +0000
>
> On 03/20/2019 05:38 PM, Eli Zaretskii wrote:
> >> Cc: tom@tromey.com, gdb-patches@sourceware.org
> >> From: Pedro Alves <palves@redhat.com>
> >> Date: Wed, 20 Mar 2019 15:46:47 +0000
> >>
> >>> I agree: the right solution would be for the Readline's SIGINT handler
> >>> to stop the main thread (e.g., by using SuspendThread).
> >>
> >> I don't sure how having the SIGINT handler stop the main thread is
> >> a 100% correct solution. By the time you stop it, the main thread can well
> >> be already running readline code, halfway through updating some data
> >> structure, even if the mainline code disabled SIGINT temporarily,
> >> with _rl_block_sigint, because by the time the mainline code calls
> >> _rl_block_sigint, the SIGINT thread may have already have been spawned.
> >
> > How is this different from what happens on Posix platforms, where the
> > SIGINT handler can be invoked at any moment, while Readline might be
> > doing anything at all?
>
> On Posix platforms the signal handler runs in the same thread as the
> mainline code. There's _never_ any parallel execution. When the
> mainline code calls _rl_block_sigint, you're absolutely sure that the
> mainline code that follows will not be running in parallel with
> a SIGINT handler.
>
> >
> >> Also, you're not ever supposed to use SuspendThread for synchronization, I
> >> believe.
> >
> > We are also not supposed to mix CRT and Win32 API functions, but we do
> > that all the time.
>
> That's not at all the same thing, I'm afraid. We're not talking about
> "in theory you shouldn't, but in practice it's OK.". We're talking about
> the very real fact that you cannot use it to synchronize correctly,
> as shown in the blog post I pasted below. If you're using the function
> to pause a thread, and then do things, but the thread doesn't actually
> pause before you do things, then you have a problem.
>
> >
> >> MSDN at <https://docs.microsoft.com/en-us/windows/desktop/api/processthreadsapi/nf-processthreadsapi-suspendthread> says:
> >>
> >> "This function is primarily designed for use by debuggers. It is not intended
> >> to be used for thread synchronization."
> >>
> >> And here <https://devblogs.microsoft.com/oldnewthing/?p=44743> it says:
> >>
> >> "The SuspendÂThread function tells the scheduler to suspend the thread
> >> but does not wait for an acknowledgment from the scheduler that the suspension
> >> has actually occurred."
> >
> > GNU Make does it for many years, and I have yet to hear a single
> > complaint about that part.
>
> Not hearing a complaint does not mean that the problem isn't real.
> It probably simply means that the race window is narrow, so the number
> of people that observe any issue, _and_ are willing to report an issue
> is small, and also, is someone notices something odd, it may be simply
> impossible to tell what happened and realize what the problem was,
> after the fact.
I'm sorry I brought this up. I should have known better.
next prev parent reply other threads:[~2019-03-20 18:01 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-30 8:57 Alan Hayward
2019-01-31 7:59 ` Joel Brobecker
2019-01-31 10:02 ` Alan Hayward
2019-01-31 17:24 ` Alan Hayward
[not found] ` <20190201080533.GA31043@adacore.com>
2019-02-01 12:47 ` Tom Tromey
2019-02-01 18:54 ` Philippe Waroquiers
2019-02-06 19:56 ` Pedro Alves
2019-03-17 17:30 ` Tom Tromey
2019-03-17 18:35 ` Eli Zaretskii
[not found] ` <87imwex333.fsf@tromey.com>
2019-03-19 18:37 ` Eli Zaretskii
2019-03-19 19:02 ` Pedro Alves
2019-03-19 19:04 ` Pedro Alves
2019-03-19 20:14 ` Eli Zaretskii
2019-03-20 8:55 ` Eli Zaretskii
2019-03-20 15:46 ` Pedro Alves
2019-03-20 15:50 ` Pedro Alves
2019-03-20 17:39 ` Eli Zaretskii
2019-03-20 17:50 ` Pedro Alves
2019-03-20 18:01 ` Eli Zaretskii [this message]
2019-03-20 18:28 ` Pedro Alves
2019-03-21 17:31 ` Pedro Alves
2019-03-21 18:30 ` Eli Zaretskii
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=83mulps9vn.fsf@gnu.org \
--to=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=palves@redhat.com \
--cc=tom@tromey.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