[glib: 1/2] tests: limit number of threads to something reasonable.



commit 05d65aec12d970a7759f0c41cd6f9315da43dc61
Author: Harald van Dijk <harald gigawatt nl>
Date:   Tue Jul 7 13:37:30 2020 +0100

    tests: limit number of threads to something reasonable.
    
    Creating 1000 threads with the default stack size of 8 MiB will fail on
    architectures with a 32-bit address space. Move up the existing THREADS
    macro and use that instead, but change its definition to 1000 if
    pointers are larger than 32 bits.
    
    Signed-off-by: Harald van Dijk <harald gigawatt nl>

 glib/tests/once.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
---
diff --git a/glib/tests/once.c b/glib/tests/once.c
index 9e6b858fd..c34156173 100644
--- a/glib/tests/once.c
+++ b/glib/tests/once.c
@@ -23,6 +23,12 @@
 
 #include <glib.h>
 
+#if GLIB_SIZEOF_VOID_P > 4
+#define THREADS 1000
+#else
+#define THREADS 100
+#endif
+
 static gpointer
 do_once (gpointer data)
 {
@@ -101,7 +107,7 @@ static void
 test_once_multi_threaded (void)
 {
   guint i;
-  GThread *threads[1000];
+  GThread *threads[THREADS];
 
   g_test_summary ("Test g_once() usage from multiple threads");
 
@@ -141,8 +147,6 @@ test_once_init_single_threaded (void)
   g_assert_cmpint (init, ==, 1);
 }
 
-#define THREADS 100
-
 static gint64 shared;
 
 static void
@@ -176,10 +180,10 @@ test_once_init_multi_threaded (void)
 
   shared = 0;
 
-  for (i = 0; i < THREADS; i++)
+  for (i = 0; i < G_N_ELEMENTS (threads); i++)
     threads[i] = g_thread_new ("once-init-multi-threaded", thread_func, NULL);
 
-  for (i = 0; i < THREADS; i++)
+  for (i = 0; i < G_N_ELEMENTS (threads); i++)
     g_thread_join (threads[i]);
 
   g_assert_cmpint (shared, ==, 42);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]