We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4097

Summary: Segmentation fault by SDL_CreateThreadWithStackSize.
Product: SDL Reporter: Dongsun Kim <keinb2>
Component: threadAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.7   
Hardware: ARM   
OS: Other   

Description Dongsun Kim 2018-02-26 02:11:15 UTC
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.
Comment 1 Sam Lantinga 2018-02-26 02:40:34 UTC
Makes sense, do you have a patch you can test with that repro case?
Comment 2 Dongsun Kim 2018-02-26 03:05:23 UTC
Yes I can test it.
My application use SIG38 for synchronization.
Sometime it makes crash.

But using SDL_SemWaitTimeout was OK because it has below loop.
    do {
        retval = sem_timedwait(&sem->sem, &ts_timeout);
    } while (retval < 0 && errno == EINTR);
Comment 3 Sam Lantinga 2018-02-26 03:50:35 UTC
Okay, that looks like a good change.
https://hg.libsdl.org/SDL/rev/29bf3038a246

Thanks!