[gtk/modern-testsuite: 4/23] testsuite: Fix race in texture-threads test




commit 64acaf99fb7ab2218d0da62dc7db495c259eb76a
Author: Benjamin Otte <otte redhat com>
Date:   Thu Sep 16 23:56:41 2021 +0200

    testsuite: Fix race in texture-threads test
    
    Threads are evil, yo.

 testsuite/gdk/texture-threads.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/testsuite/gdk/texture-threads.c b/testsuite/gdk/texture-threads.c
index 58f631c482..ca970ab3e2 100644
--- a/testsuite/gdk/texture-threads.c
+++ b/testsuite/gdk/texture-threads.c
@@ -89,20 +89,26 @@ texture_threads (void)
   ensure_texture_access (texture);
   g_assert_nonnull (gdk_gl_context_get_current ());
 
-  /* 4. Run a thread trying to download the texture */
+  /* 4. Acquire the main loop, so the run_in_thread() doesn't
+   * try to acquire it if it manages to outrace this thread.
+   */
+  g_assert_true (g_main_context_acquire (NULL));
+
+  /* 5. Run a thread trying to download the texture */
   loop = g_main_loop_new (NULL, TRUE);
   task = g_task_new (texture, NULL, texture_download_done, loop);
   g_task_run_in_thread (task, texture_download_thread);
   g_clear_object (&task);
 
-  /* 5. Run the main loop waiting for the thread to return */
+  /* 6. Run the main loop waiting for the thread to return */
   g_main_loop_run (loop);
 
-  /* 6. All good */
+  /* 7. All good */
   gsk_renderer_unrealize (gl_renderer);
   g_clear_pointer (&loop, g_main_loop_unref);
   g_clear_object (&gl_renderer);
   g_clear_object (&surface);
+  g_main_context_release (NULL);
 }
 
 int


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