[gnome-devel-docs] programming-guidelines: Fix context pushing/popping in a code example



commit a2063c0d060506b4787642df9b342ca28409dd13
Author: Philip Withnall <philip tecnocode co uk>
Date:   Wed Mar 18 00:23:48 2015 +0000

    programming-guidelines: Fix context pushing/popping in a code example
    
    For the parallel_writes_async() callback to always be invoked in
    interesting_context, as documented, we need to push the
    interesting_context as the thread-default main context before calling
    g_task_new().
    
    Spotted by Louis Wust <louiswust fastmail fm>.

 programming-guidelines/C/main-contexts.page |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
---
diff --git a/programming-guidelines/C/main-contexts.page b/programming-guidelines/C/main-contexts.page
index 587a7e7..de3b2f5 100644
--- a/programming-guidelines/C/main-contexts.page
+++ b/programming-guidelines/C/main-contexts.page
@@ -320,11 +320,15 @@ parallel_writes_async (GBytes              *data,
 {
   GTask *task;
 
+  g_main_context_push_thread_default (interesting_context);
+
   task = g_task_new (NULL, cancellable, callback, user_data);
   g_task_set_task_data (task, data,
                         (GDestroyNotify) g_bytes_unref);
   g_task_run_in_thread (task, thread_cb);
   g_object_unref (task);
+
+  g_main_context_pop_thread_default (interesting_context);
 }</code>
     </example>
 


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