Use of pthread_cancel()


 
Thread Tools Search this Thread
Top Forums Programming Use of pthread_cancel()
# 1  
Old 09-28-2005
Use of pthread_cancel()

Hi all,

I am working on a piece of multi threaded code, where I have a main thread looping in increments of 5ms, while it is waiting on a helper thread which is writing to a remote location. This helper thread keeps updating the main thread about progress of the write operation and the moment we detect a 5ms period of inactivity, we want the main thread to proceed and the helper thread to cease all operation asap. This is a timeout implementation to ensure that the remote location did not go down while we were trying to write in which case we would be hung forever. In an auxilliary scenario, the connecting link might be slow, so even though we do not write in a period of 5ms, we might not really be hung. We want to cease the helper thread neverthless.

We have concerns about using pthread_cancel() to kill the helper thread since the helper thread touches global data and works with open file descriptors. I am trying to implement appropriate cleanup, but wondering if there is an alternate healthy approach to cease operations?

Thanks!
-Rav
# 2  
Old 09-28-2005
If you understand POSIX.1 cancellation points, then you can determine when the thread will be cancelled.

Otherwise, (maybe the thread is compute bound) it won't necessarily be cancelled right when pthread_cancel is called, unless you call pthread_testcancel - assuming pthread_setcancelstate was called to allow cancellation.

The real question: is the quantum slice smaller than 5ms? If it is not then your design will probably not work as planned.
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Programming

pthread_cancel failure

I'm running a simple web server and seem to be having a problem canceling sessions. When a new request is received I start a thread to handle that session's requests. Since I want to keep the pipe open for a long time - 10 minutes or maybe 2 hours - I also have a session manager that... (4 Replies)
Discussion started by: John S.
4 Replies

2. UNIX for Advanced & Expert Users

Memory leak while using pthread_cancel()

I tried to execute a sample pthread program to cancel a newly created one using pthread_cancel(). but using valgrind on my code shows some memory leak. My Code: #include "iostream" #include "unistd.h" #include "pthread.h" #include "signal.h" using namespace std; void handler(int); void*... (4 Replies)
Discussion started by: kcr
4 Replies

3. Programming

Question: pthread_cancel() and printf()

Hello! First of all, sorry for my English, I'm not a native English speaker. I know, that printf() function uses write() function. "man cancellation" says that write() function is a cancellation point. But when I call pthread_cancel() for my thread, which calls printf() in infinite cycle, it... (4 Replies)
Discussion started by: prankster
4 Replies
Login or Register to Ask a Question