Re: how to stop a thread?



顺珉 吴 wrote:
> How can I stop a thread in time which runs in a
> forever and big loop?
> For example, in the loop the thread may be waiting for
> the return of select(), a complex calculation function
> or time-out, can I inturrupt it and made the thread
> stop just like a signal do ?

There are alot of ways to handle that situation, I personally
think its best to be cooperative with the thread and notify
the thread that it should quit; i.e. if the thread must block
on select/poll, it can also be blocking on a pipe used to trap
the "please quit" message, or optionally; if you make your thread
run its own GMainLoop/GMainContext, you could use an async queue
for the messaging.

Sometimes though, we are stuck with some kind of binary obscure
monster of a third party library that will indefinitly block
when calling the "return_a_million_rows()" function that might
have been written without considering that the application
writer might want to "Abort" the operation (I could go on ranting...)

So when all else fails, these heathens deserve the kill -9 treatment ;-p

Cheers,
                            -Tristan



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