[glib/wip/pwithnall/2456-thread-pool-fix: 1/2] gthreadpool: Remove a dummy item from the queue before freeing




commit b402f66c07a8a248c0d8f6f9f82279939190fbff
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Aug 19 14:15:37 2021 +0100

    gthreadpool: Remove a dummy item from the queue before freeing
    
    Now that `g_thread_pool_new_full()` can be used to set a user-provided
    free function for queue elements, ensure that the internal dummy item
    used to wake up the worker threads is removed from the queue before it’s
    called.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>
    
    Helps: #2456

 glib/gthreadpool.c | 5 +++++
 1 file changed, 5 insertions(+)
---
diff --git a/glib/gthreadpool.c b/glib/gthreadpool.c
index 15d5d4e52..c7d587a56 100644
--- a/glib/gthreadpool.c
+++ b/glib/gthreadpool.c
@@ -964,6 +964,11 @@ g_thread_pool_free_internal (GRealThreadPool* pool)
   g_return_if_fail (pool->running == FALSE);
   g_return_if_fail (pool->num_threads == 0);
 
+  /* Ensure the dummy item pushed on by g_thread_pool_wakeup_and_stop_all() is
+   * removed, before it’s potentially passed to the user-provided
+   * @item_free_func. */
+  g_async_queue_remove (pool->queue, GUINT_TO_POINTER (1));
+
   g_async_queue_unref (pool->queue);
   g_cond_clear (&pool->cond);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]