1 /* GTK - The GIMP Toolkit
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 GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
35 static int nthreads = 0;
36 static pthread_mutex_t nthreads_mutex = PTHREAD_MUTEX_INITIALIZER;
39 close_cb (GtkWidget *w, gint *flag)
45 delete_cb (GtkWidget *w, GdkEvent *event, gint *flag)
66 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
67 gtk_window_set_title (GTK_WINDOW (window), name);
68 gtk_widget_set_usize (window, 100, 50);
70 vbox = gtk_vbox_new (FALSE, 0);
72 g_signal_connect (window, "delete-event",
73 G_CALLBACK (delete_cb), &flag);
75 gtk_container_add (GTK_CONTAINER (window), vbox);
77 label = gtk_label_new ("0");
78 gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, FALSE, 0);
80 button = gtk_button_new_with_label ("Close");
81 g_signal_connect (button, "clicked",
82 G_CALLBACK (close_cb), &flag);
83 gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
85 gtk_widget_show_all (window);
87 /* Since flag is only checked or set inside the GTK lock,
88 * we don't have to worry about locking it explicitly
92 sprintf(buffer, "%d", counter);
93 gtk_label_set_text (GTK_LABEL (label), buffer);
96 /* Give someone else a chance to get the lock next time.
97 * Only necessary because we don't do anything else while
105 gtk_widget_destroy (window);
107 pthread_mutex_lock (&nthreads_mutex);
111 pthread_mutex_unlock (&nthreads_mutex);
121 main (int argc, char **argv)
126 if (!gdk_threads_init())
128 fprintf(stderr, "Could not initialize threads\n");
132 gtk_init (&argc, &argv);
134 pthread_mutex_lock (&nthreads_mutex);
141 sprintf(buffer[i], "Thread %i", i);
142 if (pthread_create (&thread, NULL, counter, buffer[i]))
144 fprintf(stderr, "Couldn't create thread\n");
150 pthread_mutex_unlock (&nthreads_mutex);
155 fprintf(stderr, "Done\n");
156 #else /* !USE_PTHREADS */
157 fprintf (stderr, "GTK+ not compiled with threads support\n");
159 #endif /* USE_PTHREADS */