From f9f45d0bf5932fcb49f4a90af197ba2aecf62b69 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 25 Feb 2018 19:51:34 -0800 Subject: [PATCH] Fixed bug 4097 - Segmentation fault by SDL_CreateThreadWithStackSize Dongsun Kim Normal case 1. [thread 1] SDL_CreateThreadWithStackSize calls SDL_SYS_CreateThread. 2. [thread 1] If successful, it calls SDL_SemWait. 3. [thread 2] SDL_RunThread calls SDL_SYS_SetupThread, SDL_ThreadID, SDL_SemPost. 4. [thread 1] SDL_CreateThreadWithStackSize calls SDL_DestroySemaphore, SDL_free. Crash case (Segmentation fault) 1. [thread 1] SDL_CreateThreadWithStackSize calls SDL_SYS_CreateThread. 2. [thread 1] If successful, it calls SDL_SemWait. --> Error return due to SIGNAL(SYSTEM or Real Time) at sem_wait(pthread). 3. [thread 1] SDL_CreateThreadWithStackSize calls SDL_DestroySemaphore, SDL_free. 4. [thread 2] SDL_RunThread calls SDL_SYS_SetupThread, SDL_ThreadID, SDL_SemPost. --> Segmentation fault at strlen or sem_post. --- src/thread/pthread/SDL_syssem.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/thread/pthread/SDL_syssem.c b/src/thread/pthread/SDL_syssem.c index ec8059ee728e9..bdebf1311a971 100644 --- a/src/thread/pthread/SDL_syssem.c +++ b/src/thread/pthread/SDL_syssem.c @@ -91,7 +91,10 @@ SDL_SemWait(SDL_sem * sem) return SDL_SetError("Passed a NULL semaphore"); } - retval = sem_wait(&sem->sem); + do { + retval = sem_wait(&sem->sem); + } while (retval < 0 && errno == EINTR); + if (retval < 0) { retval = SDL_SetError("sem_wait() failed"); }