| Summary: | Killing threads doesn't work on Mac OS X | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Christian Walther <cwalther> |
| Component: | thread | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED WONTFIX | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | ||
| Version: | HG 1.2 | ||
| Hardware: | PowerPC | ||
| OS: | Mac OS X 10.4 (PPC) | ||
| Attachments: | Test program | ||
|
Description
Christian Walther
2006-03-25 03:20:24 UTC
SDL_KillThread() will be deprecated and possibly removed n SDL 1.3, since there are too many cases where killing a thread is extremely dangerous. I'm not sure if it's worth fixing this at this point. If anybody knows some magic incantation to make this work, please let me know.
Did some experimentation...SDL_KillThread() is actually blocking in pthread_cancel() on an Intel iMac running 10.4.6, unless I explicitly call pthread_detach() first...detaching doesn't kill the thread, either, it just prevents SDL_KillThread() from blocking indefinitely.
Tried adding this to SDL_SYS_SetupThread() in src/threads/pthread/SDL_systhread.c, no dice, either.
pthread_setcanceltype(PTHREAD_CANCEL_ENABLE, &oldstate);
The pthread_kill() path takes down the whole process--I guess it delivers the signal to every thread on Mac OS X, or just the process generally--so I guess that's a non-starter.
If my test program added a pthread_testcancel() call to its loop, it would in fact die.
So what we could do, I guess, is this:
- Add a call to pthread_detach() right before pthread_cancel()
- Sprinkle some calls to pthread_testcancel() into a few places, like SDL_Delay(). There are several cancelation points in the C runtime (file i/o, etc), which will catch some non-SDL things, but lots of Mac OS X, unlike lots of Unix, doesn't necessarily hit these cancellation points to do common things...I suspect file i/o done at the Carbon layer won't trigger it. It also doesn't help if the thread is doing "while (1) {}".
Alternately:
- Flag this bug as WONTFIX and tell people "don't use SDL_KillThread()."
Sam, thoughts?
--ryan.
Created attachment 107 [details]
Test program
Here's my test case. Build like this:
gcc -o testkill testkill.c `sdl-config --cflags --libs`
If you want to have the thread call pthread_testcancel(), build like this:
gcc -DUSE_TESTCANCEL -o testkill testkill.c `sdl-config --cflags --libs`
--ryan.
"don't use SDL_KillThread()" |