2002-07-04 17:19:30 +02:00
|
|
|
#undef G_DISABLE_ASSERT
|
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
|
2000-04-28 14:24:53 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#define RUNS 100
|
|
|
|
|
|
|
|
G_LOCK_DEFINE_STATIC (thread_counter);
|
|
|
|
gulong abs_thread_counter;
|
|
|
|
gulong running_thread_counter;
|
2005-07-20 19:06:02 +02:00
|
|
|
gulong leftover_task_counter;
|
2000-04-28 14:24:53 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
thread_pool_func (gpointer a, gpointer b)
|
|
|
|
{
|
|
|
|
G_LOCK (thread_counter);
|
|
|
|
abs_thread_counter++;
|
|
|
|
running_thread_counter++;
|
|
|
|
G_UNLOCK (thread_counter);
|
|
|
|
|
|
|
|
g_usleep (g_random_int_range (0, 4000));
|
|
|
|
|
|
|
|
G_LOCK (thread_counter);
|
|
|
|
running_thread_counter--;
|
2005-07-20 19:06:02 +02:00
|
|
|
leftover_task_counter--;
|
2000-04-28 14:24:53 +02:00
|
|
|
G_UNLOCK (thread_counter);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc,
|
|
|
|
char *argv[])
|
|
|
|
{
|
|
|
|
/* Only run the test, if threads are enabled and a default thread
|
|
|
|
implementation is available */
|
|
|
|
#if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
|
2000-09-28 09:54:40 +02:00
|
|
|
GThreadPool *pool1, *pool2, *pool3;
|
|
|
|
guint i;
|
2000-04-28 14:24:53 +02:00
|
|
|
g_thread_init (NULL);
|
|
|
|
|
2001-05-18 10:44:57 +02:00
|
|
|
pool1 = g_thread_pool_new (thread_pool_func, NULL, 3, FALSE, NULL);
|
|
|
|
pool2 = g_thread_pool_new (thread_pool_func, NULL, 5, TRUE, NULL);
|
|
|
|
pool3 = g_thread_pool_new (thread_pool_func, NULL, 7, TRUE, NULL);
|
2000-04-28 14:24:53 +02:00
|
|
|
|
|
|
|
for (i = 0; i < RUNS; i++)
|
|
|
|
{
|
2000-09-01 15:03:23 +02:00
|
|
|
g_thread_pool_push (pool1, GUINT_TO_POINTER (1), NULL);
|
|
|
|
g_thread_pool_push (pool2, GUINT_TO_POINTER (1), NULL);
|
|
|
|
g_thread_pool_push (pool3, GUINT_TO_POINTER (1), NULL);
|
2005-07-20 19:06:02 +02:00
|
|
|
leftover_task_counter += 3;
|
2000-04-28 14:24:53 +02:00
|
|
|
}
|
|
|
|
|
2005-07-20 19:06:02 +02:00
|
|
|
g_thread_pool_free (pool1, TRUE, TRUE);
|
2000-04-28 14:24:53 +02:00
|
|
|
g_thread_pool_free (pool2, FALSE, TRUE);
|
|
|
|
g_thread_pool_free (pool3, FALSE, TRUE);
|
|
|
|
|
2005-07-20 19:06:02 +02:00
|
|
|
g_assert (RUNS * 3 == abs_thread_counter + leftover_task_counter);
|
2000-04-28 14:24:53 +02:00
|
|
|
g_assert (running_thread_counter == 0);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|