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

◆ NUMTHREADS

#define NUMTHREADS   10

Definition at line 22 of file torturethread.c.

Function Documentation

◆ main()

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

Definition at line 77 of file torturethread.c.

78{
80 int i;
81
82 /* Enable standard application logging */
84
85 /* Load the SDL library */
86 if (SDL_Init(0) < 0) {
87 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
88 return (1);
89 }
90
91 signal(SIGSEGV, SIG_DFL);
92 for (i = 0; i < NUMTHREADS; i++) {
93 char name[64];
94 SDL_snprintf(name, sizeof (name), "Parent%d", i);
97
98 if (threads[i] == NULL) {
99 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread: %s\n", SDL_GetError());
100 quit(1);
101 }
102 }
103
104 for (i = 0; i < NUMTHREADS; i++) {
106 }
107
108 for (i = 0; i < NUMTHREADS; i++) {
110 }
111 SDL_Quit();
112 return (0);
113}
unsigned int uintptr_t
#define SDL_AtomicSet
#define SDL_GetError
#define SDL_CreateThread
#define SDL_LogSetPriority
#define SDL_LogError
#define SDL_WaitThread
#define SDL_Quit
#define SDL_Init
#define SDL_snprintf
@ SDL_LOG_PRIORITY_INFO
Definition: SDL_log.h:106
@ SDL_LOG_CATEGORY_APPLICATION
Definition: SDL_log.h:66
GLuint const GLchar * name
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
Definition: SDL_x11sym.h:50
#define NULL
Definition: begin_code.h:167
static SDL_Thread * threads[6]
Definition: testlock.c:25
static void quit(int rc)
Definition: torturethread.c:28
#define NUMTHREADS
Definition: torturethread.c:22
int ThreadFunc(void *data)
Definition: torturethread.c:44
static SDL_atomic_t time_for_threads_to_die[NUMTHREADS]
Definition: torturethread.c:24

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(), threads, and time_for_threads_to_die.

◆ quit()

static void quit ( int  rc)
static

Definition at line 28 of file torturethread.c.

29{
30 SDL_Quit();
31 exit(rc);
32}

References SDL_Quit.

Referenced by main().

◆ SubThreadFunc()

int SubThreadFunc ( void data)

Definition at line 35 of file torturethread.c.

36{
37 while (!*(int volatile *) data) {
38 ; /* SDL_Delay(10); *//* do nothing */
39 }
40 return 0;
41}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974

Referenced by ThreadFunc().

◆ ThreadFunc()

int ThreadFunc ( void data)

Definition at line 44 of file torturethread.c.

45{
46 SDL_Thread *sub_threads[NUMTHREADS];
47 int flags[NUMTHREADS];
48 int i;
49 int tid = (int) (uintptr_t) data;
50
51 SDL_Log("Creating Thread %d\n", tid);
52
53 for (i = 0; i < NUMTHREADS; i++) {
54 char name[64];
55 SDL_snprintf(name, sizeof (name), "Child%d_%d", tid, i);
56 flags[i] = 0;
57 sub_threads[i] = SDL_CreateThread(SubThreadFunc, name, &flags[i]);
58 }
59
60 SDL_Log("Thread '%d' waiting for signal\n", tid);
61 while (SDL_AtomicGet(&time_for_threads_to_die[tid]) != 1) {
62 ; /* do nothing */
63 }
64
65 SDL_Log("Thread '%d' sending signals to subthreads\n", tid);
66 for (i = 0; i < NUMTHREADS; i++) {
67 flags[i] = 1;
68 SDL_WaitThread(sub_threads[i], NULL);
69 }
70
71 SDL_Log("Thread '%d' exiting!\n", tid);
72
73 return 0;
74}
#define SDL_AtomicGet
#define SDL_Log
GLbitfield flags
int SubThreadFunc(void *data)
Definition: torturethread.c:35

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

Referenced by main().

Variable Documentation

◆ time_for_threads_to_die

SDL_atomic_t time_for_threads_to_die[NUMTHREADS]
static

Definition at line 24 of file torturethread.c.

Referenced by main(), and ThreadFunc().