From: Jeff Law <jeffrey.law@oss.qualcomm.com>
To: Jan Dubiec <jdx@o2.pl>, Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] H8/300: sim: Fix simulator hang caused by qsort on Windows/MinGW.
Date: Mon, 31 Aug 2026 08:09:33 -0600 [thread overview]
Message-ID: <c517e5b7-8605-4c80-a3eb-d3e07e5320cf@oss.qualcomm.com> (raw)
In-Reply-To: <140cc872-432a-4b4d-85d6-c93ac879bafb@o2.pl>
On 8/29/26 7:40 PM, Jan Dubiec wrote:
> On 27.08.2026 17:19, Tom Tromey wrote:
>>>>>>> "Jan" == Jan Dubiec <jdx@o2.pl> writes:
>>
>> Jan> So I think the best solution is to use a sorting algorithm known
>> to be
>> Jan> stable on every host, e.g. the insertion sort implementation
>> from my
>> Jan> previous message.
>>
>> Would it be possible to change the comparison function to be stable?
>
> It is impossible by definition, because stability is a property of the
> sorting algorithm, not the comparator. However, the comparator can be
> modified in such a way that an unstable sorting algorithm produces a
> “good enough” result.
When the comparator returns "0", the order of those two elements is
unspecified in the final output of qsort. That introduces host
dependencies in behavior that we very much want to avoid.
The traditional way to fix that is to fix the comparator to not return 0
by introducing additional sort keys. He may have been a bit imprecise
by saying "change the comparison function to be stable", but the intent
is clear and consistent with how this issue has been handled through the
decades.
Jeff
next prev parent reply other threads:[~2026-08-31 14:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 11:02 Jan Dubiec
2026-08-23 20:50 ` Jan Dubiec
2026-08-27 15:19 ` Tom Tromey
2026-08-30 1:40 ` Jan Dubiec
2026-08-31 14:09 ` Jeff Law [this message]
2026-08-31 15:36 ` Jan Dubiec
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=c517e5b7-8605-4c80-a3eb-d3e07e5320cf@oss.qualcomm.com \
--to=jeffrey.law@oss.qualcomm.com \
--cc=gdb-patches@sourceware.org \
--cc=jdx@o2.pl \
--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