Skip to contentSkip to conversation

signaling a thread to stop

DISCUSSION David Eduardo Gomez Noguera 2 participants 2 messages Apr 14, 2002

lore
Share & tools
lore
#1 lore raw
In reply to David Eduardo Gomez Noguera
Quoted 5 lines · David Eduardo Gomez Noguera

I am writting a gtk program that comunicates with a pen pad. when it starts writting, it starts doing it in "real time", just as the pen moves, there is flow of data, so a toggle button creates a thread, and will need to stop it too.

Quoted 7 lines

what is the best way to do it?

i read on libc info page pthread_cancel, but didnt understand what does it exactly do.
I think it signals the thread, then the thread must tests its value to see if it has been "canceled" and decide upon an action (after the thread itself was set to CANCEL_ENABLE)what to do, am i right?

Assuming that the thread has cancellation enabled (which is the default), if the cancellation type is deferred (the default), it will be cancelled upon the next call to any of:

pthread_join
pthread_cond_wait
pthread_cond_timedwait
pthread_testcancel
sem_wait
sigwait

OTOH, if the cancellation type is set to asynchronous, with pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS), the thread will be terminated as soon as it receives the request.

Signature · 1 line
Glynn Clements <[email protected]>
#0 lore raw

Hello.
I am writting a gtk program that comunicates with a pen pad. when it starts writting, it starts doing it in "real time", just as the pen moves, there is flow of data, so a toggle button creates a thread, and will need to stop it too.

what is the best way to do it?

i read on libc info page pthread_cancel, but didnt understand what does it exactly do.
I think it signals the thread, then the thread must tests its value to see if it has been "canceled" and decide upon an action (after the thread itself was set to CANCEL_ENABLE)what to do, am i right?

the thread needs to stop comunication with the pad, so it does not keep sending data, and then flush any remaining data when asked to stop. And unlock a mutex.

Signature · 8 lines
ICQ: 15605359 Bicho
                                  =^..^=
First, they ignore you. Then they laugh at you. Then they fight you.
Then you win. Mahatma Gandhi.
-------------------------------気検体の一致------------------------------------
暑さ寒さも彼岸まで。
恋にししょうなし。恋はしあんの他。
アン アン アン とっても大好き