5 G_LOCK_DEFINE_STATIC (thread_counter);
6 gulong abs_thread_counter;
7 gulong running_thread_counter;
10 thread_pool_func (gpointer a, gpointer b)
12 G_LOCK (thread_counter);
14 running_thread_counter++;
15 G_UNLOCK (thread_counter);
17 g_usleep (g_random_int_range (0, 4000));
19 G_LOCK (thread_counter);
20 running_thread_counter--;
21 G_UNLOCK (thread_counter);
28 GThreadPool *pool1, *pool2, *pool3;
30 /* Only run the test, if threads are enabled and a default thread
31 implementation is available */
32 #if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
35 pool1 = g_thread_pool_new (thread_pool_func, 3, 0, FALSE,
36 G_THREAD_PRIORITY_NORMAL, FALSE, NULL);
37 pool2 = g_thread_pool_new (thread_pool_func, 5, 0, FALSE,
38 G_THREAD_PRIORITY_LOW, FALSE, NULL);
39 pool3 = g_thread_pool_new (thread_pool_func, 7, 0, FALSE,
40 G_THREAD_PRIORITY_LOW, TRUE, NULL);
42 for (i = 0; i < RUNS; i++)
44 g_thread_pool_push (pool1, GUINT_TO_POINTER (1));
45 g_thread_pool_push (pool2, GUINT_TO_POINTER (1));
46 g_thread_pool_push (pool3, GUINT_TO_POINTER (1));
49 g_thread_pool_free (pool1, FALSE, TRUE);
50 g_thread_pool_free (pool2, FALSE, TRUE);
51 g_thread_pool_free (pool3, FALSE, TRUE);
53 g_assert (RUNS * 3 == abs_thread_counter);
54 g_assert (running_thread_counter == 0);