File 0920-Fix-ethread_SUITE-equal_tids-test-in-system.patch of Package erlang

From d6eca176be018e8086b81d89e1787880debcfc01 Mon Sep 17 00:00:00 2001
From: Rickard Green <rickard@erlang.org>
Date: Fri, 5 Jun 2020 16:58:41 +0200
Subject: [PATCH] Fix ethread_SUITE:equal_tids test in system

---
 erts/test/ethread_SUITE_data/ethread_tests.c | 36 +++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/erts/test/ethread_SUITE_data/ethread_tests.c b/erts/test/ethread_SUITE_data/ethread_tests.c
index fe7f92b012..87f59f1adc 100644
--- a/erts/test/ethread_SUITE_data/ethread_tests.c
+++ b/erts/test/ethread_SUITE_data/ethread_tests.c
@@ -217,16 +217,23 @@ create_join_thread_test(void)
  * Tests ethr_equal_tids.
  */
 
-#define ETT_THREADS 100000
+#define ETT_THREADS 1000
 
 static ethr_tid ett_tids[3];
 static ethr_mutex ett_mutex;
 static ethr_cond ett_cond;
 static int ett_terminate;
+static int ett_thread_go;
 
 static void *
 ett_thread(void *my_tid)
 {
+    ethr_mutex_lock(&ett_mutex);
+    while (!ett_thread_go) {
+	int res = ethr_cond_wait(&ett_cond, &ett_mutex);
+	ASSERT(res == 0);
+    }
+    ethr_mutex_unlock(&ett_mutex);
 
     ASSERT(!ethr_equal_tids(ethr_self(), ett_tids[0]));
     ASSERT(ethr_equal_tids(ethr_self(), *((ethr_tid *) my_tid)));
@@ -257,18 +264,36 @@ equal_tids_test(void)
     res = ethr_cond_init(&ett_cond);
     ASSERT(res == 0);
     ett_tids[0] = ethr_self();
+
+    ethr_mutex_lock(&ett_mutex);
+    ett_thread_go = 0;
+    ethr_mutex_unlock(&ett_mutex);
     
     res = ethr_thr_create(&ett_tids[1], ett_thread, (void *) &ett_tids[1], NULL);
     ASSERT(res == 0);
 
+    ethr_mutex_lock(&ett_mutex);
+    ett_thread_go = 1;
+    ethr_cond_signal(&ett_cond);
+    ethr_mutex_unlock(&ett_mutex);
+    
     ASSERT(ethr_equal_tids(ethr_self(), ett_tids[0]));
     ASSERT(!ethr_equal_tids(ethr_self(), ett_tids[1]));
 
     res = ethr_thr_join(ett_tids[1], NULL);
 
+    ethr_mutex_lock(&ett_mutex);
+    ett_thread_go = 0;
+    ethr_mutex_unlock(&ett_mutex);
+
     res = ethr_thr_create(&ett_tids[2], ett_thread, (void *) &ett_tids[2], NULL);
     ASSERT(res == 0);
 
+    ethr_mutex_lock(&ett_mutex);
+    ett_thread_go = 1;
+    ethr_cond_signal(&ett_cond);
+    ethr_mutex_unlock(&ett_mutex);
+
     ASSERT(ethr_equal_tids(ethr_self(), ett_tids[0]));
     ASSERT(!ethr_equal_tids(ethr_self(), ett_tids[1]));
     ASSERT(!ethr_equal_tids(ethr_self(), ett_tids[2]));
@@ -294,9 +319,18 @@ equal_tids_test(void)
     ASSERT(!ethr_equal_tids(ett_tids[0], ett_tids[1]));
 
     for (i = 0; i < ETT_THREADS; i++) {
+        ethr_mutex_lock(&ett_mutex);
+        ett_thread_go = 0;
+        ethr_mutex_unlock(&ett_mutex);
+
 	res = ethr_thr_create(&ett_tids[2], ett_thread, (void*)&ett_tids[2], NULL);
 	ASSERT(res == 0);
 
+        ethr_mutex_lock(&ett_mutex);
+        ett_thread_go = 1;
+        ethr_cond_broadcast(&ett_cond);
+        ethr_mutex_unlock(&ett_mutex);
+
 	ASSERT(!ethr_equal_tids(ett_tids[0], ett_tids[2]));
 	ASSERT(!ethr_equal_tids(ett_tids[1], ett_tids[2]));
 
-- 
2.26.2

openSUSE Build Service is sponsored by