Re: [gtk-list] Problems with multithreading.



> I've changed that prog to use pthreads instead of whatever thread.hh might be

just a wrapper around calls to either pthreads or solarix threads. and
some very dumb error checking...

> and it works here on solaris and linux , even though the
> gdk_threads_enter/leave() pair in the main thread prevents the window to be
> displayed in the time the main thread is waiting, what you presumably
> intended. 

Yes. was just to make sure that no strange race condition occured.


>Other than that it does, what it should.

Damn. 
I tried with both solaris and posix threads. And it crashes all the
same.

I don't understand why!


> 
> #include <stdlib.h>
> #include <stdio.h>
> #include <pthread.h>
> 
> #include <gtk/gtk.h>
> 
> void *the_ui_thread(void *ptr)
> {
>   printf("hello\n");
> 
>   gdk_threads_enter();
>   printf("creating the window\n");
>   gtk_widget_show (gtk_window_new (GTK_WINDOW_TOPLEVEL));
>   printf("ok.\n");
>   gdk_threads_leave();
> }
> 
> int
> main (int argc, char **argv)
> {
>   pthread_t tid;
>   g_thread_init(NULL);
> 
>   /* initialise gtk */
>   //  gtk_set_locale ();
>   gtk_init (&argc, &argv);
> 
>   //  add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
>   //  add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
> 
>   gdk_threads_enter();
>   pthread_create(tid, NULL, the_ui_thread, NULL);
                  ^^^^^
you mean &tid, I guess.

> 
>   printf("zzzz...\n");
>   sleep(2);
>   printf("Now!\n");
> 
>   gtk_main ();
>   gdk_threads_leave();
> 
>   return 0;
> }
>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]