Re: Kill gthreads



        If its really just one library call or at least
one library call _Doesnt_ return.... 
(Not very g)libbish code follows ...)

static int thread_id;

void sigchld_handler(int signum) {
        waitpid(thread_id, &status, NULL);      
}


void main() {
/*...*/

        backup_handler = signal(SIGCHLD, sigchld_handler);

        if ((thread_id = fork()) == 0) {
         /*     call that might not return */
            exit();
        } else if (thread_id > 0) {
                g_timeout_add(/*you get the picture ? 
                                in here you can do 
                                "kill(thread_id, SIGTERM);" */);
        }
}


Of course if it was your code that just wont return
I'm sure you could find something alot more elegant.


        -Tristan

Johan wrote:

Hello!
I am developing a filesharing client and want to make
some dns lookups with the gethostbyname() function.
I don't want to freeze the application while doing
this and i belive the best way to resolve the ips
with gethostbyname is to create a thread by using the
g_thread-library.

My problem is that I want to kill the thread if the
dns lookup takes to long time or the user cancels
the connection attempt, and I cant find a way
to do this.

Is it impossible to kill the g-thread? If it is, do
anyone have a better way to solve the dns lookup?

Thanks
Johan Nilsson
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



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