From 8ac11176ab38858bb14b47881a2ef7ed1ed0c7c7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 20 Jul 2005 17:06:02 +0000 Subject: [PATCH] Don't get stuck in here if immediate is TRUE. (#310954, Hong Jen Yee) 2005-07-20 Matthias Clasen * glib/gthreadpool.c (g_thread_pool_free): Don't get stuck in here if immediate is TRUE. (#310954, Hong Jen Yee) * tests/threadpool-test.c (main): Test immediate == TRUE. --- ChangeLog | 8 ++++++++ ChangeLog.pre-2-10 | 8 ++++++++ ChangeLog.pre-2-12 | 8 ++++++++ ChangeLog.pre-2-8 | 8 ++++++++ glib/gthreadpool.c | 11 +++++++++-- tests/threadpool-test.c | 7 +++++-- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index af2cbecf..0bb46297 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-07-20 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-20 Tor Lillqvist * glib/gutils.h (g_win32_get_system_data_dirs): Make this an diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index af2cbecf..0bb46297 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,11 @@ +2005-07-20 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-20 Tor Lillqvist * glib/gutils.h (g_win32_get_system_data_dirs): Make this an diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index af2cbecf..0bb46297 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,11 @@ +2005-07-20 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-20 Tor Lillqvist * glib/gutils.h (g_win32_get_system_data_dirs): Make this an diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index af2cbecf..0bb46297 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,11 @@ +2005-07-20 Matthias Clasen + + * glib/gthreadpool.c (g_thread_pool_free): Don't get + stuck in here if immediate is TRUE. (#310954, + Hong Jen Yee) + + * tests/threadpool-test.c (main): Test immediate == TRUE. + 2005-07-20 Tor Lillqvist * glib/gutils.h (g_win32_get_system_data_dirs): Make this an diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c index 16156518..bd8df74d 100644 --- a/glib/gthreadpool.c +++ b/glib/gthreadpool.c @@ -79,6 +79,7 @@ g_thread_pool_thread_proxy (gpointer data) gboolean goto_global_pool = !pool->pool.exclusive; gint len = g_async_queue_length_unlocked (pool->queue); + g_print ("thread pool proxy loop\n"); if (g_thread_should_run (pool, len)) { if (watcher) @@ -118,13 +119,16 @@ g_thread_pool_thread_proxy (gpointer data) len = g_async_queue_length_unlocked (pool->queue); } + g_print ("queue len %d\n", len); if (!g_thread_should_run (pool, len)) { + g_print ("shouldn't run, go to global pool\n"); g_cond_broadcast (inform_cond); goto_global_pool = TRUE; } else if (len > 0) { + g_print ("should run, don't go to global pool\n"); /* At this pool there are no threads waiting, but tasks are. */ goto_global_pool = FALSE; } @@ -134,6 +138,7 @@ g_thread_pool_thread_proxy (gpointer data) * just return from a timed wait. We now wait for a limited * time at this pool for new tasks to avoid costly context * switches. */ + g_print ("no threads, no tasks, wait for a while\n"); goto_global_pool = FALSE; watcher = TRUE; } @@ -545,7 +550,8 @@ g_thread_pool_free (GThreadPool *pool, if (wait) { g_mutex_lock (inform_mutex); - while (g_async_queue_length_unlocked (real->queue) != -real->num_threads) + while (g_async_queue_length_unlocked (real->queue) != -real->num_threads && + !(immediate && real->num_threads == 0)) { g_async_queue_unlock (real->queue); g_cond_wait (inform_cond, inform_mutex); @@ -554,7 +560,8 @@ g_thread_pool_free (GThreadPool *pool, g_mutex_unlock (inform_mutex); } - if (g_async_queue_length_unlocked (real->queue) == -real->num_threads) + if (immediate || + g_async_queue_length_unlocked (real->queue) == -real->num_threads) { /* No thread is currently doing something (and nothing is left * to process in the queue) */ diff --git a/tests/threadpool-test.c b/tests/threadpool-test.c index 47748400..95993e8f 100644 --- a/tests/threadpool-test.c +++ b/tests/threadpool-test.c @@ -8,6 +8,7 @@ G_LOCK_DEFINE_STATIC (thread_counter); gulong abs_thread_counter; gulong running_thread_counter; +gulong leftover_task_counter; void thread_pool_func (gpointer a, gpointer b) @@ -21,6 +22,7 @@ thread_pool_func (gpointer a, gpointer b) G_LOCK (thread_counter); running_thread_counter--; + leftover_task_counter--; G_UNLOCK (thread_counter); } @@ -44,13 +46,14 @@ main (int argc, 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); + leftover_task_counter += 3; } - g_thread_pool_free (pool1, FALSE, TRUE); + g_thread_pool_free (pool1, TRUE, TRUE); g_thread_pool_free (pool2, FALSE, TRUE); g_thread_pool_free (pool3, FALSE, TRUE); - g_assert (RUNS * 3 == abs_thread_counter); + g_assert (RUNS * 3 == abs_thread_counter + leftover_task_counter); g_assert (running_thread_counter == 0); #endif return 0; -- 2.34.1