On 7 Jul, 2004, at 17:23, Jim Magee wrote: Using Mach APIs directly to undermine the POSIX libraries is a good way to lead to memory leakage, corruption, and or crashes. In particular, there is no good way to use the Mach thread termination APIs without confusing the pthread layer. What is the thread doing when you want to kill it? If it is looping, can you add a call to pthread_testcancel()? If not, can you take a directed signal (pthread_kill()) and convert that into something you check for clean termination (after releasing locks, etc... held by the target thread). I'm porting a little othello game I had to write at a computer science course. So I got the main thread and one that is playing the game. If the user wants to play a new game then I have to kill the game thread (or at least restart it). => So the thread I want to kill is either listening on a condition 'pthread_cond_wait()' (Human, mouse click) or it is calculating some game-trees for AI. Because its variables are no more needed in the next game, I think it would be save to kill immediatly.
From your mail, I can see the following options. Correct me if I'm wrong.
1. Calling pthread_testcancel() during the thread. If I want to kill, call pthread_cancel followed by a broadcast on the condition variable in case the thread is waiting. I think it's a little annoying always calling pthread_testcancel() all the time. And If I do, how expensive would that be? 2. Forget about posix threads and work directly with Mach threads (thought they look a little complicated comparing to the pthreads => Is there any example code out there?). 3. Live with the memory leak (probably not the best solution) -- Christoph _______________________________________________ darwin-kernel mailing list | darwin-kernel@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel Do not post admin requests to the list. They will be ignored.
participants (1)
-
Christoph Nägeli