Hello,
reading the C99 standard, section 7.14.1.1 paragraph 5, I infer that
calling raise in a signal handler exercises undefined behavior.
I came across this when porting SDL (SVN trunk) to OpenWatcom/Win32.
Everything is fine so far, except some missing calling convention
specifiers and testlock crashing on exit. (More on this in another thread.)
Here is a patch that fixes the terminate function for the testlock test.
Note, that I left closemutex alone, although it also boldly exercises
undefined behavior. There might be a line-wrap near the end of the patch
that Thunderbird inserted:
--------------- 8< ---------------
Index: testlock.c===================================================================
— testlock.c (revision 2328)
+++ testlock.c (working copy)
@@ -14,6 +14,7 @@
static SDL_mutex *mutex = NULL;
static Uint32 mainthread;
static SDL_Thread *threads[6];
+static volatile sig_atomic_t doterminate = 0;
/*
- SDL_Quit() shouldn’t be used with atexit() directly because
@@ -31,8 +32,7 @@
void terminate(int sig)
{
- printf(“Process %u: raising SIGTERM\n”, SDL_ThreadID());
- raise(SIGTERM);
- doterminate = 1;
}
void closemutex(int sig)
{
@@ -44,7 +44,7 @@
SDL_DestroyMutex(mutex);
exit(sig);
}
-int Run(void *data)
+int SDLCALL Run(void data)
{
if ( SDL_ThreadID() == mainthread )
signal(SIGTERM, closemutex);
@@ -63,6 +63,10 @@
}
/ If this sleep isn’t done, then threads may starve */
SDL_Delay(10); -
if (SDL_ThreadID() == mainthread && doterminate) {
-
printf("Process %u: raising SIGTERM\n", SDL_ThreadID());
-
raise(SIGTERM);
-
}}
return(0);
}
--------------- 8< ---------------
Cheers
Marc
–
Marc Peter