Re: how to leave a specific thread?
- From: Sergei Steshenko <sergstesh yahoo com>
- To: gtk-list gnome org, frederico schardong <frede sch gmail com>
- Subject: Re: how to leave a specific thread?
- Date: Sat, 11 Jul 2009 14:30:32 -0700 (PDT)
--- On Sat, 7/11/09, frederico schardong <frede sch gmail com> wrote:
> From: frederico schardong <frede sch gmail com>
> Subject: how to leave a specific thread?
> To: gtk-list gnome org
> Date: Saturday, July 11, 2009, 12:08 PM
> 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
You can still use global variables, and threads can monitor their value.
Kinda signals.
Or I'm getting it wrong ?
Regards,
Sergei.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]