static void test_g_static_private (void) { GThread *threads[THREADS]; guint i; test_g_static_private_ready = 0; for (i = 0; i < THREADS; i++) { threads[i] = g_thread_create (test_g_static_private_thread, GINT_TO_POINTER (i), TRUE, NULL); } /* Busy wait is not nice but that's just a test */ while (test_g_static_private_ready != THREADS) g_usleep (G_USEC_PER_SEC / 5); /* Reuse the static private */ g_static_private_free (&test_g_static_private_private2); g_static_private_init (&test_g_static_private_private2); test_g_static_private_ready = 0; for (i = 0; i < THREADS; i++) g_assert (GPOINTER_TO_INT (g_thread_join (threads[i])) == i * 3); g_assert (test_g_static_private_counter == 0); }
static void testcase (void) { g_test_bug ("642026"); mutex = g_mutex_new (); cond = g_cond_new (); g_mutex_lock (mutex); for (i = 0; i < ITERATIONS; i++) { GThread *t1; g_static_private_init (&sp); freed = 0; t1 = g_thread_create (thread_func, NULL, TRUE, NULL); g_assert (t1 != NULL); /* wait for t1 to set up its thread-private data */ g_cond_wait (cond, mutex); /* exercise the bug, by racing with t1 to free the private data */ g_static_private_free (&sp); g_thread_join (t1); } g_cond_free (cond); g_mutex_unlock (mutex); g_mutex_free (mutex); }
/* initialize thread-local storage */ static gpointer authldap_once(gpointer UNUSED data) { g_static_private_init(&ldap_conn_key); __auth_get_config(); return (gpointer)NULL; }