From: Fabien Chouteau <chouteau@adacore.com>
To: "Stefan Weil" <sw@weilnetz.de>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Ян Завадовский" <zavadovsky.yan@gmail.com>
Cc: Olivier Hainque <hainque@adacore.com>,
QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] thread-win32: fix GetThreadContext() permanently fails
Date: Wed, 24 Jun 2015 11:09:00 +0200 [thread overview]
Message-ID: <558A73AC.303@adacore.com> (raw)
In-Reply-To: <55899261.6020705@weilnetz.de>
On 06/23/2015 07:07 PM, Stefan Weil wrote:
> Am 23.06.2015 um 12:46 schrieb Paolo Bonzini:
>> On 23/06/2015 12:30, Peter Maydell wrote:
>>> On 23 June 2015 at 10:55, Ян Завадовский <zavadovsky.yan@gmail.com> wrote:
>>>> On Tue, Jun 23, 2015 at 9:02 AM, Stefan Weil <sw@weilnetz.de> wrote:
>>>>> We should add an URL to reliable documentation which supports that
>>>>> claim.
>>>> Unfortunately, MSDN says only "SuspendThread suspends the thread. It's
>>>> designed for debuggers. Don't use in applications.":
>>>> https://msdn.microsoft.com/en-us/library/windows/desktop/ms686345(v=vs.85).aspx
>>>> And nothing more useful.
>>>> So when I found this piece of code with Suspend/Resume and failed GetContext
>>>> I did some googling.
>>>> And found this article:
>>>> http://blogs.msdn.com/b/oldnewthing/archive/2015/02/05/10591215.aspx
>>> Personally I am happy to treat a Raymond Chen blog post as "reliable
>>> documentation"...
>> Me too. :)
>
> +1
>
> Fabien, I wonder why nobody noticed that the current
> code did not do what it was written for. As far as I see
> the threads were created with the wrong options, so
> GetThreadContext always failed and therefore was only
> executed once, so there was no waiting for thread
> suspension.
>
I'm surprised as well, but we run several hundred thousands of tests
every day (one QEMU instance for each test) and before this fix we had a
few instances freezing for no reason. We identified a possible race
condition on SMP host and the bug disappeared after this fix.
Even if the call was erroneous, adding a call to GetThreadContext
probably gave more time or forced the suspend request to be effective,
it's the only explanation I have right now.
But clearly there was a bug, and the call to GetThreadContext fixed it.
I found other pieces of code that uses this technique but calling
GetThreadContext only once (not in a loop like we did), so maybe it's
enough to call it once and the loop is superfluous...
> Removing the code would have given identical results.
>
Considering we are talking about thread synchronization on Windows and
SMP host, I would not make that assumption :)
> Is that in an indicator that the SuspendThread is not
> needed at all, as it was discussed in the other e-mails
> here?
If we completely change the thread synchronization on Windows, maybe
SuspendeThread is not needed anymore, but with the current scheme (at
least what I know of it), I don't see how we can remove it.
As I said before we must be very careful with this piece of code.
Regards,
next prev parent reply other threads:[~2015-06-24 9:09 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-22 21:54 [Qemu-devel] [PATCH] thread-win32: fix GetThreadContext() permanently fails Zavadovsky Yan
2015-06-23 6:02 ` Stefan Weil
2015-06-23 9:49 ` Fabien Chouteau
2015-06-23 10:11 ` Ян Завадовский
2015-06-23 9:55 ` Ян Завадовский
2015-06-23 10:30 ` Peter Maydell
2015-06-23 10:46 ` Paolo Bonzini
2015-06-23 11:18 ` Daniel P. Berrange
2015-06-23 11:32 ` Paolo Bonzini
2015-06-23 11:43 ` Daniel P. Berrange
2015-06-23 11:52 ` Paolo Bonzini
2015-06-23 11:23 ` Peter Maydell
2015-06-23 17:07 ` Stefan Weil
2015-06-24 9:09 ` Fabien Chouteau [this message]
2015-06-24 10:03 ` Peter Maydell
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=558A73AC.303@adacore.com \
--to=chouteau@adacore.com \
--cc=hainque@adacore.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
--cc=zavadovsky.yan@gmail.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 NNTP newsgroup(s).