09-28-2005
6,
0
Join Date: Sep 2005
Last Activity: 11 May 2007, 8:05 AM EDT
Posts: 6
Thanks Given: 0
Thanked 0 Times in 0 Posts
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