Threads & Glade




Hi, this is my first post here. I have a problem programming an interface, by glade , for a multithread 
written code(using pthreads.h). The interface is done and works well for a single thread. Calling more than 
one thread simultaneously gtk aborts the application. 
this is main.c

#ifdef HAVE_CONFIG_H
#  include 
#endif

#include 
#include 
#include "interface.h"
#include "support.h"

pthread_cond_t cond=PTHREAD_COND_INITIALIZER;

void * function (void * ptr);

int
main (int argc, char *argv[])
{
        pthread_t id[4];
        int rec[4];
        int count;
        count=0;
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif

        while(count<2){
        if(rec[count]=pthread_create ( &id[count] , NULL , (void *) &function, (void *) NULL)!=0) 
printf("CIAOOOO\n");
                count++;
                sleep(5);
        }
        sleep (100);
        return 0;
}


void * function (void * ptr){

        GtkWidget *window;
                
        gtk_set_locale ();
        gtk_init (NULL, NULL);
        add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
        window = create_window1 ();
        gtk_widget_show (window);
        gtk_main();
        return;
}
 
As you can see it's simple but it is just a test.
I also tried by forking the code and in this case all worsk well, but i can't use fork() in the multithread 
code. How can I call my interface for every new thread without conflict?
--
Sent from the Gtk+ - Apps Dev forum at Nabble.com:
http://www.nabble.com/Threads-Glade-t364295.html#a1009083



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