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 /* Only run the test, if threads are enabled and a default thread
29 implementation is available */
30 #if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
31 GThreadPool *pool1, *pool2, *pool3;
35 pool1 = g_thread_pool_new (thread_pool_func, NULL, 3, FALSE, NULL);
36 pool2 = g_thread_pool_new (thread_pool_func, NULL, 5, TRUE, NULL);
37 pool3 = g_thread_pool_new (thread_pool_func, NULL, 7, TRUE, NULL);
39 for (i = 0; i < RUNS; i++)
41 g_thread_pool_push (pool1, GUINT_TO_POINTER (1), NULL);
42 g_thread_pool_push (pool2, GUINT_TO_POINTER (1), NULL);
43 g_thread_pool_push (pool3, GUINT_TO_POINTER (1), NULL);
46 g_thread_pool_free (pool1, FALSE, TRUE);
47 g_thread_pool_free (pool2, FALSE, TRUE);
48 g_thread_pool_free (pool3, FALSE, TRUE);
50 g_assert (RUNS * 3 == abs_thread_counter);
51 g_assert (running_thread_counter == 0);