875 Subj : pthreads - cancellation To : comp.programming.threads From : plinius Date : Sat Aug 20 2005 07:33 pm Hi, I have a difficult problem: I'm using pthreads with a communication-librarie. This librarie has blocking Recv's. When a "cummunicator" (you can see it as a radio-frequency) changes, I have to repost the Recv, because soon after it changed, the old one becomes invalid. The Recv function is of the following form: Recv(int number, comm communicator). Hence I can't let the thread know it should be restarted with a dummy-message, because every possible value for "number" is valid. So I can't initiate the thread-restart from "within" the thread which should be restarted... I've red here http://groups.google.be/group/comp.programming.threads/browse_frm/thread/10721b0bac88e1d0/7007305bfbeea1bf?hl=nl#7007305bfbeea1bf that you can't just kill the thread. Allso it seems that cancellation is really tricky (and not allways possible, and never advisable). Is it possible to stop a thread from another one? Suppose I have the following case: A,B,C are blocked by a recv. The communicator of B changes. D wants to kill and restart thread B so that it's healthy again. How should I do that? Has anyone experience with something like that? Can someone give me a code sample? Please note, I don't want B to become inactive, but I want it killed. Not that it matters (I think), but I'm using http://sources.redhat.com/pthreads-win32/ If something's not clear, please ask it... Any input is greatly appreciated. ________________________ int main(int argc, char* argv[]) { pthread_t thread[4]; int status; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_JOINABLE); pthread_create(&thread[0],&attr,A,NULL); pthread_create(&thread[1],&attr,B,NULL); pthread_create(&thread[2],&attr,C,NULL); pthread_create(&thread[3],&attr,D,NULL); pthread_join(thread[0],(void**)&status); pthread_join(thread[1],(void**)&status); pthread_join(thread[2],(void**)&status); pthread_join(thread[3],(void**)&status); pthread_attr_destroy(&attr); pthread_exit(NULL); } . 0