Search This Blog

Saturday, October 31, 2009

Thread, Four Ways to Kill A Thread

1. hard kill -- don't do this, it might corrupt the original process or worst
2. cancel point -- must abort at some point, like pthread_cancel. once canceled, cannot be undone. (p148, pthread)
3. exception support -- the target thread, at certain cancellation point, might throw exception, , after being "asked" to cancel/abort/interrupt. You then can write try-catch to do clean up work. or even ignore the cancel request. Therefore, the cancel request might not be honored, and not deterministic. (if your last catch block takes 10 year to run :)
4. co-operate threads -- thread can communicate with each other (check shared memory location, global variable, etc). real example: once you cancel the firefox download job, the downloading thread is still downloading! the target thread can check the tread state later (am i being canceled after it fetches 1mb of data). If I am asked to shutdown, kill myself, or return this thread to the thread pool, so other tasks can use it


http://stackoverflow.com/questions/1327102/how-to-kill-a-thread-instantly-in-c
http://www.ddj.com/architect/207100682

No comments: