1 /* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GLib Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GLib at ftp://ftp.gtk.org/pub/gtk/.
29 #include <sys/types.h>
39 get_a_child (gint ttl)
55 child_watch_callback (GPid pid, gint status, gpointer data)
57 g_print ("child %d exited, status %d\n", pid, status);
60 g_main_loop_quit (main_loop);
66 test_thread (gpointer data)
68 GMainLoop *new_main_loop;
71 gint ttl = GPOINTER_TO_INT (data);
73 new_main_loop = g_main_loop_new (NULL, FALSE);
75 pid = get_a_child (ttl);
76 source = g_child_watch_source_new (pid);
77 g_source_set_callback (source, (GSourceFunc) child_watch_callback, NULL, NULL);
78 g_source_attach (source, g_main_loop_get_context (new_main_loop));
79 g_source_unref (source);
81 g_print ("whee! created pid: %d\n", pid);
82 g_main_loop_run (new_main_loop);
87 main (int argc, char *argv[])
89 /* Only run the test, if threads are enabled and a default thread
90 implementation is available */
91 #if defined(G_THREADS_ENABLED) && ! defined(G_THREADS_IMPL_NONE)
93 main_loop = g_main_loop_new (NULL, FALSE);
98 g_thread_create (test_thread, GINT_TO_POINTER (10), FALSE, NULL);
99 g_thread_create (test_thread, GINT_TO_POINTER (20), FALSE, NULL);
101 g_main_loop_run (main_loop);