I don't understand your question... aside from the fact that the example starts 
two threads that would never end without killing/signaling the process, I do 
think you're example looks fine. Or is your question: can a combination of 
usleep calls and gdk threads cause problems? In that case I can't help you (a 
quick look on google gave me this link 
http://man.chinaunix.net/develop/GTK+/2.6/gdk/gdk-Threads.html)

Regards,
Douwe Vos



----- Original Message ----
From: frederico schardong <[email protected]>
To: [email protected]
Sent: Tuesday, July 14, 2009 2:50:50 AM
Subject: error with thread

Hi,

I have a so big function (near 600 lines) and it communicates with
some embedded system using serial port... this function have some ties
(for and while).. and a great number of usleep...

When I call this function, GTK windows and widgets are lost.. and this
mustn't be happen... to resolve this I'm using threads like this
example:

/* Compile me with:
*  gcc -o sample3 sample3.c $(pkg-config --cflags --libs gtk+-2.0 gthread-2.0)
*/
#include <gtk/gtk.h>

static gpointer
thread_func( gpointer data )
{
    while( TRUE )
    {
        usleep( 500000 );

        gdk_threads_enter();
        g_print("\naa");
        gdk_threads_leave();
    }

    return( NULL );
}

static gpointer
thread_func1( gpointer data )
{
    while( TRUE )
    {
        sleep( 1 );

        gdk_threads_enter();
        g_print("\nbb");
        gdk_threads_leave();
    }

    return( NULL );
}

int
main( int    argc,
      char **argv )
{
    GThread   *thread, *th;
    GError    *error = NULL;

    /* Secure glib */
    if( ! g_thread_supported() )
        g_thread_init( NULL );

    /* Secure gtk */
    gdk_threads_init();

    /* Obtain gtk's global lock */
    gdk_threads_enter();

    /* Do stuff as usual */
    gtk_init( &argc, &argv );

    /* Create new thread */
    thread = g_thread_create( thread_func, NULL,
                              FALSE, &error );
    if( ! thread )
    {
        g_print( "Error: %s\n", error->message );
        return( -1 );
    }

    /* Create new thread */
    th = g_thread_create( thread_func1, NULL,
                              FALSE, &error );
    if( ! th )
    {
        g_print( "Error: %s\n", error->message );
        return( -1 );
    }

    gtk_main();

    /* Release gtk's global lock */
    gdk_threads_leave();

    return( 0 );
}

//end

I'm using exactly like this example, but all stopped widgets keep
going like before.. have this function any limitations about ties
number (for, while) or time under the while(1) of the thread?

Thanks!

-- 
Abraço,
Frederico Schardong,
SOLIS - O lado livre da tecnologia
www.solis.coop.br
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list



      
_______________________________________________
gtk-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-list

Reply via email to