bug in thread-test.c
- From: Miroslaw Dobrzanski-Neumann <mne mosaic-ag com>
- To: GTKDEV <gtk-devel-list gnome org>
- Subject: bug in thread-test.c
- Date: Tue, 12 Feb 2002 14:22:41 +0100
Hi,
threre is a bug in glib-1.3.13/tests/thread-test.c
9 static gpointer
10 test_g_mutex_thread (gpointer data)
11 {
12 g_assert (GPOINTER_TO_INT (data) == 42);
13 g_assert (g_mutex_trylock (test_g_mutex_mutex) == FALSE);
14 g_assert (G_TRYLOCK (test_g_mutex) == FALSE);
15 g_mutex_lock (test_g_mutex_mutex);
16 g_assert (test_g_mutex_int == 42);
17 g_mutex_unlock (test_g_mutex_mutex);
18
19 return GINT_TO_POINTER (41);
20 }
21
22 static void
23 test_g_mutex (void)
24 {
25 GThread *thread;
26 test_g_mutex_mutex = g_mutex_new ();
27
28 g_assert (g_mutex_trylock (test_g_mutex_mutex));
29 g_assert (G_TRYLOCK (test_g_mutex));
30 thread = g_thread_create (test_g_mutex_thread, GINT_TO_POINTER (42),
31 TRUE, NULL);
32 g_usleep (G_USEC_PER_SEC);
33 test_g_mutex_int = 42;
34 G_UNLOCK (test_g_mutex);
35 g_mutex_unlock (test_g_mutex_mutex);
36 g_assert (GPOINTER_TO_INT (g_thread_join (thread)) == 41);
37 g_mutex_free (test_g_mutex_mutex);
38 }
line 32
You can not expect that after G_USEC_PER_SEC the thread running
test_g_mutex_thread() get executed. Sleep is the wrong solution for thread
synchronization. If test_g_mutex_thread() is scheduled after
line 35 the thest fails in line 13.
You should use g_thread_join() instead.
regards.
--
Miroslaw Dobrzanski-Neumann
MOSAIC SOFTWARE AG
Base Development and Research
Tel +49-2225-882-291
Fax +49-2225-882-201
E-mail: mne mosaic-ag com
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]