| Summary: | SDL_SemWaitTimeout generic implementation is wrong | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Henrik Kouri <henrik.kouri> |
| Component: | thread | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | critical | ||
| Priority: | P2 | CC: | sezeroz |
| Version: | 1.2.13 | Keywords: | target-1.2.14 |
| Hardware: | All | ||
| OS: | All | ||
Tagging this bug with "target-1.2.14" so we can try to resolve it for SDL 1.2.14. Please note that we may choose to resolve it as WONTFIX. This tag is largely so we have a comprehensive wishlist of bugs to examine for 1.2.14 (and so we can close bugs that we'll never fix, rather than have them live forever in Bugzilla). --ryan. Fixed in subversion, thanks! |
SDL_SemWaitTimeout in src/thread/generic/SDL_syssem.c line 179 (SVN trunk): --sem->count; should be if (retval == 0) { --sem->count; } Without this, sem->count will underflow on timeout effectively breaking the semaphore. It appears that the implementation has been wrong since the initial revision. Below is a sample C++ app to demonstrate the problem (should output plain zeros when correct): #include <SDL.h> #include <iostream> int main(int argc, char* argv[]) { SDL_Init(0); SDL_sem* sem = SDL_CreateSemaphore(0); std::cout << SDL_SemValue(sem) << std::endl; SDL_SemTryWait(sem); std::cout << SDL_SemValue(sem) << std::endl; SDL_SemTryWait(sem); std::cout << SDL_SemValue(sem) << std::endl; // Breaks here! Integer underflows! SDL_SemWaitTimeout(sem, 10); std::cout << SDL_SemValue(sem) << std::endl; SDL_SemTryWait(sem); std::cout << SDL_SemValue(sem) << std::endl; SDL_SemTryWait(sem); std::cout << SDL_SemValue(sem) << std::endl; SDL_DestroySemaphore(sem); sem = NULL; SDL_Quit(); return 0; }