Re: Question about Threads y gtk+



Richard Boaz wrote:
> Inexplicably (read: I don't know), there is no glib equivalent for the
> function pthread_kill().
>   

Blowing a thread's brains out is generally a bad idea.  The whole idea
of threads is that they share address spaces and if you kill them at
arbitrary times it's not impossible that the thread was in the middle
of, e.g., updating something critical.

The only safe way to kill a thread is by asking it politely to die.  
Depending on the circumstances, you can use things like glib
asynchronous queues, g_io_add_watch() on a pipe channel, Linux/UNIX
tkill() (that can make your code non-portable--the way you get the
thread IDs isn't (yet) uniform), standard Linux/UNIX pipes and select()
or poll(), as Mr Boaz suggests, a shared flag, etc., etc.

> Not sure why, perhaps the glib gurus could elaborate on why it is not
> possible to externally kill a thread a la pthread_kill()?
>
> Or is there some equivalent I have not found?
>
> Assuming there is no glib thread kill function, you've got to get creative
> here: let the thread complete and then ignore its results, or,
> periodically read a queue that the main thread writes to telling the
> thread it needs to quit, or, periodically read a global flag, etc.
>
> richard
>
> On Fri, Oct 3, 2008 at 1:56 AM, Moises <ammoises yahoo com mx> wrote:
>
>     Question about Threads y gtk+
>
>     To end a thread, you have to leave the function of the thread with an
> exit, return  or calling g_thread_exit.
>
>     My question is how can I finish the thread from my main thread?
>
>     I try to use g_object_unref, for finish the thread but get me error.
>
>
>
>
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
>
>   


-- 
Moller Software Development Services

*Christian H. L. Moller*
/President/

*Moller Software Development Services, LLC*

**
moller mollerware com 	   	919.367.8689 (Voice)
www.mollerware.com <http://www.mollerware.com> 	   	919.367.9097 (Fax)

** **


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