libstdc++: testsuite: call sched_yield for nonpreemptive targets

Message ID ortu8ed0lk.fsf@lxoliva.fsfla.org
State Committed
Commit f129628e8f261b66a34a9626e1f5b0293548a6a8
Headers
Series libstdc++: testsuite: call sched_yield for nonpreemptive targets |

Commit Message

Alexandre Oliva June 21, 2022, 5:52 a.m. UTC
  As in the gcc testsuite, systems without preemptive multi-threading
require sched_yield calls to be placed at points in which a context
switch might be needed to enable the test to complete.

Regstrapped on x86_64-linux-gnu, also tested with a cross to
aarch64-rtems6.  Ok to install?


for  libstdc++-v3/ChangeLog

	* testsuite/30_threads/this_thread/60421.cc (test02): Call
	sched_yield.
---
 .../testsuite/30_threads/this_thread/60421.cc      |    1 +
 1 file changed, 1 insertion(+)
  

Comments

Jonathan Wakely June 21, 2022, 7:38 a.m. UTC | #1
On Tue, 21 Jun 2022 at 06:54, Alexandre Oliva via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
>
>
> As in the gcc testsuite, systems without preemptive multi-threading
> require sched_yield calls to be placed at points in which a context
> switch might be needed to enable the test to complete.

I'll try to remember that, but will probably forget. Is this really
the only affected test?

>
> Regstrapped on x86_64-linux-gnu, also tested with a cross to
> aarch64-rtems6.  Ok to install?

OK, thanks.
  
Alexandre Oliva June 22, 2022, 12:20 a.m. UTC | #2
On Jun 21, 2022, Jonathan Wakely <jwakely@redhat.com> wrote:

> On Tue, 21 Jun 2022 at 06:54, Alexandre Oliva via Libstdc++
> <libstdc++@gcc.gnu.org> wrote:
>> 
>> 
>> As in the gcc testsuite, systems without preemptive multi-threading
>> require sched_yield calls to be placed at points in which a context
>> switch might be needed to enable the test to complete.

> I'll try to remember that, but will probably forget. Is this really
> the only affected test?

Yeah, the only one in libstdc++-v3/testsuite, as of gcc-11, which is
what I've focused on for this project; I haven't gone through all fails
on master to make sure they're unrelated.  (This is holding up some
filesystem-related patches, whose tests are failing for reasons not
present in gcc-11, and some of the forward-ports needed significant
rewriting.)

libstdc++ has plenty of threading tests, but they involve sleeping or
otherwise blocking, which offers a context switch opportunity even on
non-preemptive multithreading systems.  It's busy waits that require a
sched_yield.  The gcc testsuite has a handful of those; covered by a
separate patch also posted last night.
  

Patch

diff --git a/libstdc++-v3/testsuite/30_threads/this_thread/60421.cc b/libstdc++-v3/testsuite/30_threads/this_thread/60421.cc
index ad6f9aeffcc80..12dbeba1cc492 100644
--- a/libstdc++-v3/testsuite/30_threads/this_thread/60421.cc
+++ b/libstdc++-v3/testsuite/30_threads/this_thread/60421.cc
@@ -59,6 +59,7 @@  test02()
   while (!sleeping)
   {
     // Wait for the thread to start sleeping.
+    sched_yield ();
   }
   while (sleeping)
   {