Don't be clever, just call it testthread
authorSam Lantinga <slouken@libsdl.org>
Fri, 25 Mar 2011 11:09:57 -0700
changeset 550860b63c32f06d
parent 5507 6275a16e63c2
child 5509 5b1b4d820d10
Don't be clever, just call it testthread
Xcode-iPhoneOS/Test/README
Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj
Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj
test/Makefile.in
test/testhread.c
test/testthread.c
     1.1 --- a/Xcode-iPhoneOS/Test/README	Fri Mar 25 10:54:13 2011 -0700
     1.2 +++ b/Xcode-iPhoneOS/Test/README	Fri Mar 25 11:09:57 2011 -0700
     1.3 @@ -3,7 +3,7 @@
     1.4  testalpha:
     1.5  	Program crashes.  Problem appears to effect Mac OS X as well.
     1.6  
     1.7 -testhread:
     1.8 +testthread:
     1.9  	SIGTERM kills the process immediately without executing the 'kill' function.  The posix standard says this shouldn't happen.  Apple seems intent on having iPhone apps exit promptly when the user requests it, so maybe that's why(?)
    1.10  
    1.11  testlock:
    1.12 @@ -19,4 +19,4 @@
    1.13  	Behaves as it does under Mac OS X ... not sure if that is correctly or not.
    1.14  
    1.15  threadwin:
    1.16 -	Works if -threaded is not on.  Otherwise it doesn't work, but this is true under Mac OS X as well.
    1.17 \ No newline at end of file
    1.18 +	Works if -threaded is not on.  Otherwise it doesn't work, but this is true under Mac OS X as well.
     2.1 --- a/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Fri Mar 25 10:54:13 2011 -0700
     2.2 +++ b/Xcode-iPhoneOS/Test/TestiPhoneOS.xcodeproj/project.pbxproj	Fri Mar 25 11:09:57 2011 -0700
     2.3 @@ -180,7 +180,7 @@
     2.4  		FDD2C1040E2E4F4B00B7A85F /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89C0E2D111A00EA573E /* UIKit.framework */; };
     2.5  		FDD2C1050E2E4F4B00B7A85F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89D0E2D111A00EA573E /* Foundation.framework */; };
     2.6  		FDD2C1060E2E4F4B00B7A85F /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89E0E2D111A00EA573E /* CoreAudio.framework */; };
     2.7 -		FDD2C10D0E2E4F6900B7A85F /* testhread.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A74C0E2D0F1600EA573E /* testhread.c */; };
     2.8 +		FDD2C10D0E2E4F6900B7A85F /* testthread.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA8A74C0E2D0F1600EA573E /* testthread.c */; };
     2.9  		FDD2C1770E2E52C000B7A85F /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8980E2D111A00EA573E /* AudioToolbox.framework */; };
    2.10  		FDD2C1780E2E52C000B7A85F /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A8990E2D111A00EA573E /* QuartzCore.framework */; };
    2.11  		FDD2C1790E2E52C000B7A85F /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FDA8A89A0E2D111A00EA573E /* OpenGLES.framework */; };
    2.12 @@ -329,7 +329,7 @@
    2.13  		FDA8A7470E2D0F1600EA573E /* testerror.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testerror.c; path = ../../test/testerror.c; sourceTree = SOURCE_ROOT; };
    2.14  		FDA8A7480E2D0F1600EA573E /* testfile.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testfile.c; path = ../../test/testfile.c; sourceTree = SOURCE_ROOT; };
    2.15  		FDA8A7490E2D0F1600EA573E /* testgamma.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testgamma.c; path = ../../test/testgamma.c; sourceTree = SOURCE_ROOT; };
    2.16 -		FDA8A74C0E2D0F1600EA573E /* testhread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testhread.c; path = ../../test/testhread.c; sourceTree = SOURCE_ROOT; };
    2.17 +		FDA8A74C0E2D0F1600EA573E /* testthread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testthread.c; path = ../../test/testthread.c; sourceTree = SOURCE_ROOT; };
    2.18  		FDA8A74D0E2D0F1600EA573E /* testiconv.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testiconv.c; path = ../../test/testiconv.c; sourceTree = SOURCE_ROOT; };
    2.19  		FDA8A74E0E2D0F1600EA573E /* testjoystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testjoystick.c; path = ../../test/testjoystick.c; sourceTree = SOURCE_ROOT; };
    2.20  		FDA8A74F0E2D0F1600EA573E /* testkeys.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testkeys.c; path = ../../test/testkeys.c; sourceTree = SOURCE_ROOT; };
    2.21 @@ -381,7 +381,7 @@
    2.22  		FDAAC6290E2D5960001DB1D8 /* testgles.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testgles.c; path = ../../test/testgles.c; sourceTree = SOURCE_ROOT; };
    2.23  		FDC430000F0D866D009C87E1 /* torturethread.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = torturethread.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.24  		FDC430090F0D86BF009C87E1 /* testdraw2.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testdraw2.c; path = ../../test/testdraw2.c; sourceTree = SOURCE_ROOT; };
    2.25 -		FDD2C10A0E2E4F4B00B7A85F /* testhread.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testhread.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.26 +		FDD2C10A0E2E4F4B00B7A85F /* testthread.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testthread.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.27  		FDD2C1810E2E52C000B7A85F /* testiconv.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testiconv.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.28  		FDD2C18A0E2E52FE00B7A85F /* utf8.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = utf8.txt; path = ../../test/utf8.txt; sourceTree = SOURCE_ROOT; };
    2.29  		FDD2C1A50E2E534F00B7A85F /* testjoystick.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testjoystick.app; sourceTree = BUILT_PRODUCTS_DIR; };
    2.30 @@ -866,7 +866,7 @@
    2.31  				FDAAC5C90E2D55B5001DB1D8 /* testfile.app */,
    2.32  				FDAAC5FA0E2D5843001DB1D8 /* testgamma.app */,
    2.33  				FDAAC6260E2D5914001DB1D8 /* testgles.app */,
    2.34 -				FDD2C10A0E2E4F4B00B7A85F /* testhread.app */,
    2.35 +				FDD2C10A0E2E4F4B00B7A85F /* testthread.app */,
    2.36  				FDD2C1810E2E52C000B7A85F /* testiconv.app */,
    2.37  				FDD2C1A50E2E534F00B7A85F /* testjoystick.app */,
    2.38  				FDD2C45E0E2E773800B7A85F /* testkeys.app */,
    2.39 @@ -928,7 +928,7 @@
    2.40  				FDA8A7490E2D0F1600EA573E /* testgamma.c */,
    2.41  				046CEF8913254F63007AD51D /* testgesture.c */,
    2.42  				FDAAC6290E2D5960001DB1D8 /* testgles.c */,
    2.43 -				FDA8A74C0E2D0F1600EA573E /* testhread.c */,
    2.44 +				FDA8A74C0E2D0F1600EA573E /* testthread.c */,
    2.45  				FDA8A74D0E2D0F1600EA573E /* testiconv.c */,
    2.46  				FDA8A74E0E2D0F1600EA573E /* testjoystick.c */,
    2.47  				FDA8A74F0E2D0F1600EA573E /* testkeys.c */,
    2.48 @@ -1257,9 +1257,9 @@
    2.49  			productReference = FDC430000F0D866D009C87E1 /* torturethread.app */;
    2.50  			productType = "com.apple.product-type.application";
    2.51  		};
    2.52 -		FDD2C0F90E2E4F4B00B7A85F /* testhread */ = {
    2.53 +		FDD2C0F90E2E4F4B00B7A85F /* testthread */ = {
    2.54  			isa = PBXNativeTarget;
    2.55 -			buildConfigurationList = FDD2C1070E2E4F4B00B7A85F /* Build configuration list for PBXNativeTarget "testhread" */;
    2.56 +			buildConfigurationList = FDD2C1070E2E4F4B00B7A85F /* Build configuration list for PBXNativeTarget "testthread" */;
    2.57  			buildPhases = (
    2.58  				FDD2C0FA0E2E4F4B00B7A85F /* Resources */,
    2.59  				FDD2C0FB0E2E4F4B00B7A85F /* Sources */,
    2.60 @@ -1269,9 +1269,9 @@
    2.61  			);
    2.62  			dependencies = (
    2.63  			);
    2.64 -			name = testhread;
    2.65 +			name = testthread;
    2.66  			productName = TestiPhoneOS;
    2.67 -			productReference = FDD2C10A0E2E4F4B00B7A85F /* testhread.app */;
    2.68 +			productReference = FDD2C10A0E2E4F4B00B7A85F /* testthread.app */;
    2.69  			productType = "com.apple.product-type.application";
    2.70  		};
    2.71  		FDD2C1700E2E52C000B7A85F /* testiconv */ = {
    2.72 @@ -1535,7 +1535,7 @@
    2.73  				FDAAC5B80E2D55B5001DB1D8 /* testfile */,
    2.74  				FDAAC5E90E2D5843001DB1D8 /* testgamma */,
    2.75  				046CEF7513254F23007AD51D /* testgesture */,
    2.76 -				FDD2C0F90E2E4F4B00B7A85F /* testhread */,
    2.77 +				FDD2C0F90E2E4F4B00B7A85F /* testthread */,
    2.78  				FDD2C1700E2E52C000B7A85F /* testiconv */,
    2.79  				FDD2C1930E2E534F00B7A85F /* testjoystick */,
    2.80  				FDD2C44D0E2E773800B7A85F /* testkeys */,
    2.81 @@ -1933,7 +1933,7 @@
    2.82  			isa = PBXSourcesBuildPhase;
    2.83  			buildActionMask = 2147483647;
    2.84  			files = (
    2.85 -				FDD2C10D0E2E4F6900B7A85F /* testhread.c in Sources */,
    2.86 +				FDD2C10D0E2E4F6900B7A85F /* testthread.c in Sources */,
    2.87  			);
    2.88  			runOnlyForDeploymentPostprocessing = 0;
    2.89  		};
    2.90 @@ -2506,7 +2506,7 @@
    2.91  				GCC_PRECOMPILE_PREFIX_HEADER = YES;
    2.92  				GCC_PREFIX_HEADER = "";
    2.93  				INFOPLIST_FILE = Info.plist;
    2.94 -				PRODUCT_NAME = testhread;
    2.95 +				PRODUCT_NAME = testthread;
    2.96  			};
    2.97  			name = Debug;
    2.98  		};
    2.99 @@ -2518,7 +2518,7 @@
   2.100  				GCC_PRECOMPILE_PREFIX_HEADER = YES;
   2.101  				GCC_PREFIX_HEADER = "";
   2.102  				INFOPLIST_FILE = Info.plist;
   2.103 -				PRODUCT_NAME = testhread;
   2.104 +				PRODUCT_NAME = testthread;
   2.105  			};
   2.106  			name = Release;
   2.107  		};
   2.108 @@ -3016,7 +3016,7 @@
   2.109  			defaultConfigurationIsVisible = 0;
   2.110  			defaultConfigurationName = Release;
   2.111  		};
   2.112 -		FDD2C1070E2E4F4B00B7A85F /* Build configuration list for PBXNativeTarget "testhread" */ = {
   2.113 +		FDD2C1070E2E4F4B00B7A85F /* Build configuration list for PBXNativeTarget "testthread" */ = {
   2.114  			isa = XCConfigurationList;
   2.115  			buildConfigurations = (
   2.116  				FDD2C1080E2E4F4B00B7A85F /* Debug */,
     3.1 --- a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj	Fri Mar 25 10:54:13 2011 -0700
     3.2 +++ b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj	Fri Mar 25 11:09:57 2011 -0700
     3.3 @@ -606,7 +606,7 @@
     3.4  		BEC567010761D90300A33029 /* testerror.c in Sources */ = {isa = PBXBuildFile; fileRef = 083E4878006D85357F000001 /* testerror.c */; };
     3.5  		BEC5670E0761D90400A33029 /* testgamma.c in Sources */ = {isa = PBXBuildFile; fileRef = 083E487A006D85477F000001 /* testgamma.c */; };
     3.6  		BEC5671C0761D90400A33029 /* testgl.c in Sources */ = {isa = PBXBuildFile; fileRef = 092D6D4EFFB311087F000001 /* testgl.c */; };
     3.7 -		BEC567290761D90400A33029 /* testhread.c in Sources */ = {isa = PBXBuildFile; fileRef = 092D6D58FFB311A97F000001 /* testhread.c */; };
     3.8 +		BEC567290761D90400A33029 /* testthread.c in Sources */ = {isa = PBXBuildFile; fileRef = 092D6D58FFB311A97F000001 /* testthread.c */; };
     3.9  		BEC567360761D90400A33029 /* testjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = 092D6D62FFB312AA7F000001 /* testjoystick.c */; };
    3.10  		BEC567430761D90400A33029 /* testkeys.c in Sources */ = {isa = PBXBuildFile; fileRef = 092D6D6CFFB313437F000001 /* testkeys.c */; };
    3.11  		BEC567500761D90400A33029 /* testlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 092D6D75FFB313BB7F000001 /* testlock.c */; };
    3.12 @@ -1535,7 +1535,7 @@
    3.13  		092D6D1BFFB30C237F000001 /* graywin.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = graywin.c; path = ../../test/graywin.c; sourceTree = SOURCE_ROOT; };
    3.14  		092D6D25FFB30D1A7F000001 /* testbitmap.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testbitmap.c; path = ../../test/testbitmap.c; sourceTree = SOURCE_ROOT; };
    3.15  		092D6D4EFFB311087F000001 /* testgl.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testgl.c; path = ../../test/testgl.c; sourceTree = SOURCE_ROOT; };
    3.16 -		092D6D58FFB311A97F000001 /* testhread.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testhread.c; path = ../../test/testhread.c; sourceTree = SOURCE_ROOT; };
    3.17 +		092D6D58FFB311A97F000001 /* testthread.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testthread.c; path = ../../test/testthread.c; sourceTree = SOURCE_ROOT; };
    3.18  		092D6D62FFB312AA7F000001 /* testjoystick.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testjoystick.c; path = ../../test/testjoystick.c; sourceTree = SOURCE_ROOT; };
    3.19  		092D6D6CFFB313437F000001 /* testkeys.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testkeys.c; path = ../../test/testkeys.c; sourceTree = SOURCE_ROOT; };
    3.20  		092D6D75FFB313BB7F000001 /* testlock.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = testlock.c; path = ../../test/testlock.c; sourceTree = SOURCE_ROOT; };
    3.21 @@ -2505,7 +2505,7 @@
    3.22  				092D6D4EFFB311087F000001 /* testgl.c */,
    3.23  				0017972710742FB900F5D044 /* testgl2.c */,
    3.24  				0017974E1074315700F5D044 /* testhaptic.c */,
    3.25 -				092D6D58FFB311A97F000001 /* testhread.c */,
    3.26 +				092D6D58FFB311A97F000001 /* testthread.c */,
    3.27  				002F343609CA1F6F00EBEB88 /* testiconv.c */,
    3.28  				00179791107432FA00F5D044 /* testime.c */,
    3.29  				001797B31074339C00F5D044 /* testintersections.c */,
    3.30 @@ -4626,7 +4626,7 @@
    3.31  			isa = PBXSourcesBuildPhase;
    3.32  			buildActionMask = 2147483647;
    3.33  			files = (
    3.34 -				BEC567290761D90400A33029 /* testhread.c in Sources */,
    3.35 +				BEC567290761D90400A33029 /* testthread.c in Sources */,
    3.36  			);
    3.37  			runOnlyForDeploymentPostprocessing = 0;
    3.38  		};
     4.1 --- a/test/Makefile.in	Fri Mar 25 10:54:13 2011 -0700
     4.2 +++ b/test/Makefile.in	Fri Mar 25 11:09:57 2011 -0700
     4.3 @@ -29,8 +29,8 @@
     4.4  	testgl2$(EXE) \
     4.5  	testgles$(EXE) \
     4.6  	testhaptic$(EXE) \
     4.7 -   testrumble$(EXE) \
     4.8 -	testhread$(EXE) \
     4.9 +	testrumble$(EXE) \
    4.10 +	testthread$(EXE) \
    4.11  	testiconv$(EXE) \
    4.12  	testime$(EXE) \
    4.13  	testintersections$(EXE) \
    4.14 @@ -141,7 +141,7 @@
    4.15  testrumble$(EXE): $(srcdir)/testrumble.c
    4.16  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    4.17  
    4.18 -testhread$(EXE): $(srcdir)/testhread.c
    4.19 +testthread$(EXE): $(srcdir)/testthread.c
    4.20  	$(CC) -o $@ $? $(CFLAGS) $(LIBS)
    4.21  
    4.22  testiconv$(EXE): $(srcdir)/testiconv.c
     5.1 --- a/test/testhread.c	Fri Mar 25 10:54:13 2011 -0700
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,76 +0,0 @@
     5.4 -
     5.5 -/* Simple test of the SDL threading code */
     5.6 -
     5.7 -#include <stdio.h>
     5.8 -#include <stdlib.h>
     5.9 -#include <signal.h>
    5.10 -
    5.11 -#include "SDL.h"
    5.12 -#include "SDL_thread.h"
    5.13 -
    5.14 -static int alive = 0;
    5.15 -
    5.16 -/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    5.17 -static void
    5.18 -quit(int rc)
    5.19 -{
    5.20 -    SDL_Quit();
    5.21 -    exit(rc);
    5.22 -}
    5.23 -
    5.24 -int SDLCALL
    5.25 -ThreadFunc(void *data)
    5.26 -{
    5.27 -    printf("Started thread %s: My thread id is %lu\n",
    5.28 -           (char *) data, SDL_ThreadID());
    5.29 -    while (alive) {
    5.30 -        printf("Thread '%s' is alive!\n", (char *) data);
    5.31 -        SDL_Delay(1 * 1000);
    5.32 -    }
    5.33 -    printf("Thread '%s' exiting!\n", (char *) data);
    5.34 -    return (0);
    5.35 -}
    5.36 -
    5.37 -static void
    5.38 -killed(int sig)
    5.39 -{
    5.40 -    printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
    5.41 -    SDL_Delay(5 * 1000);
    5.42 -    alive = 0;
    5.43 -    quit(0);
    5.44 -}
    5.45 -
    5.46 -int
    5.47 -main(int argc, char *argv[])
    5.48 -{
    5.49 -    SDL_Thread *thread;
    5.50 -
    5.51 -    /* Load the SDL library */
    5.52 -    if (SDL_Init(0) < 0) {
    5.53 -        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    5.54 -        return (1);
    5.55 -    }
    5.56 -
    5.57 -    alive = 1;
    5.58 -    thread = SDL_CreateThread(ThreadFunc, "#1");
    5.59 -    if (thread == NULL) {
    5.60 -        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    5.61 -        quit(1);
    5.62 -    }
    5.63 -    SDL_Delay(5 * 1000);
    5.64 -    printf("Waiting for thread #1\n");
    5.65 -    alive = 0;
    5.66 -    SDL_WaitThread(thread, NULL);
    5.67 -
    5.68 -    alive = 1;
    5.69 -    signal(SIGTERM, killed);
    5.70 -    thread = SDL_CreateThread(ThreadFunc, "#2");
    5.71 -    if (thread == NULL) {
    5.72 -        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    5.73 -        quit(1);
    5.74 -    }
    5.75 -    raise(SIGTERM);
    5.76 -
    5.77 -    SDL_Quit();                 /* Never reached */
    5.78 -    return (0);                 /* Never reached */
    5.79 -}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/test/testthread.c	Fri Mar 25 11:09:57 2011 -0700
     6.3 @@ -0,0 +1,76 @@
     6.4 +
     6.5 +/* Simple test of the SDL threading code */
     6.6 +
     6.7 +#include <stdio.h>
     6.8 +#include <stdlib.h>
     6.9 +#include <signal.h>
    6.10 +
    6.11 +#include "SDL.h"
    6.12 +#include "SDL_thread.h"
    6.13 +
    6.14 +static int alive = 0;
    6.15 +
    6.16 +/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
    6.17 +static void
    6.18 +quit(int rc)
    6.19 +{
    6.20 +    SDL_Quit();
    6.21 +    exit(rc);
    6.22 +}
    6.23 +
    6.24 +int SDLCALL
    6.25 +ThreadFunc(void *data)
    6.26 +{
    6.27 +    printf("Started thread %s: My thread id is %lu\n",
    6.28 +           (char *) data, SDL_ThreadID());
    6.29 +    while (alive) {
    6.30 +        printf("Thread '%s' is alive!\n", (char *) data);
    6.31 +        SDL_Delay(1 * 1000);
    6.32 +    }
    6.33 +    printf("Thread '%s' exiting!\n", (char *) data);
    6.34 +    return (0);
    6.35 +}
    6.36 +
    6.37 +static void
    6.38 +killed(int sig)
    6.39 +{
    6.40 +    printf("Killed with SIGTERM, waiting 5 seconds to exit\n");
    6.41 +    SDL_Delay(5 * 1000);
    6.42 +    alive = 0;
    6.43 +    quit(0);
    6.44 +}
    6.45 +
    6.46 +int
    6.47 +main(int argc, char *argv[])
    6.48 +{
    6.49 +    SDL_Thread *thread;
    6.50 +
    6.51 +    /* Load the SDL library */
    6.52 +    if (SDL_Init(0) < 0) {
    6.53 +        fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
    6.54 +        return (1);
    6.55 +    }
    6.56 +
    6.57 +    alive = 1;
    6.58 +    thread = SDL_CreateThread(ThreadFunc, "#1");
    6.59 +    if (thread == NULL) {
    6.60 +        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    6.61 +        quit(1);
    6.62 +    }
    6.63 +    SDL_Delay(5 * 1000);
    6.64 +    printf("Waiting for thread #1\n");
    6.65 +    alive = 0;
    6.66 +    SDL_WaitThread(thread, NULL);
    6.67 +
    6.68 +    alive = 1;
    6.69 +    signal(SIGTERM, killed);
    6.70 +    thread = SDL_CreateThread(ThreadFunc, "#2");
    6.71 +    if (thread == NULL) {
    6.72 +        fprintf(stderr, "Couldn't create thread: %s\n", SDL_GetError());
    6.73 +        quit(1);
    6.74 +    }
    6.75 +    raise(SIGTERM);
    6.76 +
    6.77 +    SDL_Quit();                 /* Never reached */
    6.78 +    return (0);                 /* Never reached */
    6.79 +}