1 #undef G_DISABLE_ASSERT
8 G_LOCK_DEFINE_STATIC (thread_counter);
9 gulong abs_thread_counter;
10 gulong running_thread_counter;
11 gulong leftover_task_counter;
14 thread_pool_func (gpointer a, gpointer b)
16 G_LOCK (thread_counter);
18 running_thread_counter++;
19 G_UNLOCK (thread_counter);
21 g_usleep (g_random_int_range (0, 4000));
23 G_LOCK (thread_counter);
24 running_thread_counter--;
25 leftover_task_counter--;
26 G_UNLOCK (thread_counter);
33 /* Only run the test, if threads are enabled and a default thread
34 implementation is available */
35 #if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
36 GThreadPool *pool1, *pool2, *pool3;
40 pool1 = g_thread_pool_new (thread_pool_func, NULL, 3, FALSE, NULL);
41 pool2 = g_thread_pool_new (thread_pool_func, NULL, 5, TRUE, NULL);
42 pool3 = g_thread_pool_new (thread_pool_func, NULL, 7, TRUE, NULL);
44 for (i = 0; i < RUNS; i++)
46 g_thread_pool_push (pool1, GUINT_TO_POINTER (1), NULL);
47 g_thread_pool_push (pool2, GUINT_TO_POINTER (1), NULL);
48 g_thread_pool_push (pool3, GUINT_TO_POINTER (1), NULL);
49 leftover_task_counter += 3;
52 g_thread_pool_free (pool1, TRUE, TRUE);
53 g_thread_pool_free (pool2, FALSE, TRUE);
54 g_thread_pool_free (pool3, FALSE, TRUE);
56 g_assert (RUNS * 3 == abs_thread_counter + leftover_task_counter);
57 g_assert (running_thread_counter == 0);