how to leave a specific thread?



I'm using this example of threads..

/* 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 );
}


And I must know how I can stop some thread without stop all the
others? Just stop one thread, not all

-- 
Abraço,
Frederico Schardong,
SOLIS - O lado livre da tecnologia
www.solis.coop.br


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