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>
This commit is contained in:
Harald van Dijk 2020-07-07 13:37:30 +01:00
parent 4486ac1448
commit 05d65aec12
No known key found for this signature in database
GPG Key ID: 7D71BB318A5BD56D

View File

@ -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);