Changed unportable __FUNCTION__ to the verbatim function name.
[glib.git] / tests / threadpool-test.c
blob9fa1cf141a6b1f0ff50a15d410d03746172b659b
1 #include <glib.h>
3 #define RUNS 100
5 G_LOCK_DEFINE_STATIC (thread_counter);
6 gulong abs_thread_counter;
7 gulong running_thread_counter;
9 void
10 thread_pool_func (gpointer a, gpointer b)
12 G_LOCK (thread_counter);
13 abs_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);
24 int
25 main (int argc,
26 char *argv[])
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;
32 guint i;
33 g_thread_init (NULL);
35 pool1 = g_thread_pool_new (thread_pool_func, 3, 0, FALSE,
36 G_THREAD_PRIORITY_NORMAL, FALSE, NULL, NULL);
37 pool2 = g_thread_pool_new (thread_pool_func, 5, 0, FALSE,
38 G_THREAD_PRIORITY_LOW, FALSE, NULL, NULL);
39 pool3 = g_thread_pool_new (thread_pool_func, 7, 0, FALSE,
40 G_THREAD_PRIORITY_LOW, TRUE, NULL, NULL);
42 for (i = 0; i < RUNS; i++)
44 g_thread_pool_push (pool1, GUINT_TO_POINTER (1), NULL);
45 g_thread_pool_push (pool2, GUINT_TO_POINTER (1), NULL);
46 g_thread_pool_push (pool3, GUINT_TO_POINTER (1), NULL);
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);
55 #endif
56 return 0;