2006-12-10 08:54:35 -08:00
|
|
|
/*
|
|
|
|
* testthreads.c
|
|
|
|
*
|
2007-06-24 10:56:20 -07:00
|
|
|
* Copyright (C) 2004-2007 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
2006-12-10 08:54:35 -08:00
|
|
|
*
|
2007-06-24 10:56:20 -07:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-12-10 08:54:35 -08:00
|
|
|
*
|
|
|
|
* See COPYING file that comes with this distribution.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "mooutils/mooutils-thread.h"
|
|
|
|
#include "mooutils/mooutils-misc.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
callback (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
thread_main (gpointer data)
|
|
|
|
{
|
2006-12-10 14:53:57 -08:00
|
|
|
guint i;
|
|
|
|
|
2006-12-10 08:54:35 -08:00
|
|
|
/* g_print may not be used here */
|
|
|
|
printf ("thread %d: starting\n", GPOINTER_TO_UINT (data));
|
2006-12-10 14:53:57 -08:00
|
|
|
|
|
|
|
for (i = 0; i < 10; ++i)
|
|
|
|
{
|
|
|
|
_moo_message_async ("thread %d: hi there #%d", GPOINTER_TO_UINT (data), i);
|
|
|
|
g_usleep (g_random_int_range (10, 100) * 1000);
|
|
|
|
gdk_threads_enter ();
|
|
|
|
_moo_message ("thread %d: hi there #%d again", GPOINTER_TO_UINT (data), i);
|
|
|
|
gdk_threads_leave ();
|
|
|
|
g_usleep (g_random_int_range (10, 100) * 1000);
|
|
|
|
}
|
|
|
|
|
2006-12-10 08:54:35 -08:00
|
|
|
printf ("thread %d: exiting\n", GPOINTER_TO_UINT (data));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_thread_init (NULL);
|
|
|
|
gdk_threads_init ();
|
|
|
|
gdk_threads_enter ();
|
|
|
|
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
moo_set_log_func_window (TRUE);
|
|
|
|
|
|
|
|
_moo_message ("Hi there");
|
|
|
|
|
|
|
|
_moo_event_queue_connect ((MooEventQueueCallback) callback, NULL, NULL);
|
|
|
|
|
|
|
|
for (i = 0; i < 10; ++i)
|
|
|
|
if (!g_thread_create (thread_main, GUINT_TO_POINTER (i), FALSE, NULL))
|
|
|
|
g_error ("%s", error->message);
|
|
|
|
|
|
|
|
gtk_main ();
|
|
|
|
gdk_threads_leave ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|