SDL  2.0
torturethread.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include "SDL.h"
+ Include dependency graph for torturethread.c:

Go to the source code of this file.

Macros

#define NUMTHREADS   10

Functions

static void quit (int rc)
int SubThreadFunc (void *data)
int ThreadFunc (void *data)
int main (int argc, char *argv[])

Variables

static SDL_atomic_t time_for_threads_to_die [NUMTHREADS]

Macro Definition Documentation

#define NUMTHREADS   10

Definition at line 22 of file torturethread.c.

Referenced by main(), and ThreadFunc().

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 77 of file torturethread.c.

References i, NULL, NUMTHREADS, quit(), SDL_AtomicSet, SDL_CreateThread, SDL_GetError, SDL_Init, SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, SDL_LogError, SDL_LogSetPriority, SDL_Quit, SDL_snprintf, SDL_WaitThread, ThreadFunc(), and threads.

{
int i;
/* Enable standard application logging */
/* Load the SDL library */
if (SDL_Init(0) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
return (1);
}
signal(SIGSEGV, SIG_DFL);
for (i = 0; i < NUMTHREADS; i++) {
char name[64];
SDL_snprintf(name, sizeof (name), "Parent%d", i);
threads[i] = SDL_CreateThread(ThreadFunc, name, (void*) (uintptr_t) i);
if (threads[i] == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
quit(1);
}
}
for (i = 0; i < NUMTHREADS; i++) {
}
for (i = 0; i < NUMTHREADS; i++) {
SDL_WaitThread(threads[i], NULL);
}
return (0);
}
static void quit ( int  rc)
static

Definition at line 28 of file torturethread.c.

References SDL_Quit.

{
exit(rc);
}
int SubThreadFunc ( void data)

Definition at line 35 of file torturethread.c.

Referenced by ThreadFunc().

{
while (!*(int volatile *) data) {
; /* SDL_Delay(10); *//* do nothing */
}
return 0;
}
int ThreadFunc ( void data)

Definition at line 44 of file torturethread.c.

References i, NULL, NUMTHREADS, SDL_AtomicGet, SDL_CreateThread, SDL_Log, SDL_snprintf, SDL_WaitThread, and SubThreadFunc().

{
SDL_Thread *sub_threads[NUMTHREADS];
int i;
int tid = (int) (uintptr_t) data;
SDL_Log("Creating Thread %d\n", tid);
for (i = 0; i < NUMTHREADS; i++) {
char name[64];
SDL_snprintf(name, sizeof (name), "Child%d_%d", tid, i);
flags[i] = 0;
sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
}
SDL_Log("Thread '%d' waiting for signal\n", tid);
while (SDL_AtomicGet(&time_for_threads_to_die[tid]) != 1) {
; /* do nothing */
}
SDL_Log("Thread '%d' sending signals to subthreads\n", tid);
for (i = 0; i < NUMTHREADS; i++) {
flags[i] = 1;
SDL_WaitThread(sub_threads[i], NULL);
}
SDL_Log("Thread '%d' exiting!\n", tid);
return 0;
}

Variable Documentation

SDL_atomic_t time_for_threads_to_die[NUMTHREADS]
static

Definition at line 24 of file torturethread.c.