diff options
author | Emmanuele Bassi <ebassi@gmail.com> | 2022-12-19 13:53:52 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@gmail.com> | 2022-12-19 13:53:52 +0000 |
commit | 5701a15ae32ff689b107dd03bc50f2968bfbf242 (patch) | |
tree | 24af4dd87272e99bc54aa7eecad12d7fac004d84 | |
parent | d0f456a5048ab6fbb990af09e40589b2ad2050ca (diff) | |
parent | b4ecb604aa7eb5609b272b4237e3b1c490991045 (diff) | |
download | glib-5701a15ae32ff689b107dd03bc50f2968bfbf242.tar.gz |
Merge branch 'wip/pwithnall/debugging-macos-ci' into 'main'
tests: Fix stall/deadlock in slice-concurrent on macOS CI
See merge request GNOME/glib!3152
-rw-r--r-- | glib/tests/slice-concurrent.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/glib/tests/slice-concurrent.c b/glib/tests/slice-concurrent.c index b20a62e77..241d36cd1 100644 --- a/glib/tests/slice-concurrent.c +++ b/glib/tests/slice-concurrent.c @@ -43,24 +43,25 @@ thread_func (void *arg) { int i; struct ThreadData *td = arg; + GRand *thread_rand = g_rand_new (); for (i = 0; i < N_ALLOCS; i++) { int bytes, f, t; char *mem; - if (g_random_int_range (0, N_ALLOCS / 20) == 0) + if (g_rand_int_range (thread_rand, 0, N_ALLOCS / 20) == 0) g_test_message ("%c", 'a' - 1 + td->thread_id); /* allocate block of random size and randomly fill */ - bytes = g_random_int_range (0, MAX_BLOCK_SIZE + 1); + bytes = g_rand_int_range (thread_rand, 0, MAX_BLOCK_SIZE) + 1; mem = g_slice_alloc (bytes); for (f = 0; f < bytes; f++) - mem[f] = (char) g_random_int (); + mem[f] = (char) g_rand_int (thread_rand); /* associate block with random thread */ - t = g_random_int_range (0, N_THREADS); + t = g_rand_int_range (thread_rand, 0, N_THREADS); g_mutex_lock (&tdata[t].to_free_mutex); tdata[t].to_free[tdata[t].n_to_free] = mem; tdata[t].bytes_to_free[tdata[t].n_to_free] = bytes; @@ -68,9 +69,9 @@ thread_func (void *arg) g_mutex_unlock (&tdata[t].to_free_mutex); /* shuffle thread execution order every once in a while */ - if (g_random_int_range (0, 97) == 0) + if (g_rand_int_range (thread_rand, 0, 97) == 0) { - if (g_random_boolean ()) + if (g_rand_boolean (thread_rand)) g_thread_yield(); /* concurrent shuffling for single core */ else g_usleep (1000); /* concurrent shuffling for multi core */ @@ -88,6 +89,8 @@ thread_func (void *arg) g_mutex_unlock (&td->to_free_mutex); } + g_rand_free (thread_rand); + return NULL; } |