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 1426 - SDL_SemWaitTimeout returns -1 and sets error instead of SDL_MUTEX_TIMEDOUT on time out
Summary: SDL_SemWaitTimeout returns -1 and sets error instead of SDL_MUTEX_TIMEDOUT on...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: thread (show other bugs)
Version: 1.2.15
Hardware: x86 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-19 19:01 UTC by deraj
Modified: 2012-02-20 20:52 UTC (History)
0 users

See Also:


Attachments
Fix to treat ETIMEDOUT as a time out instead of an error (and update the test) (1.60 KB, patch)
2012-02-19 19:01 UTC, deraj
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description deraj 2012-02-19 19:01:08 UTC
Created attachment 824 [details]
Fix to treat ETIMEDOUT as a time out instead of an error (and update the test)

Using SDL 1.2.15 on Linux, SDL_SemWaitTimeout appears to return -1 when I was expecting SDL_MUTEX_TIMEDOUT. I don't see this issue on 1.2.14.

According to the documentation for SDL_SemWaitTimeout, it should return 0 if successfully locked, SDL_MUTEX_TIMEDOUT (1) if timed out, and -1 on error.

However, after debugging in GDB, what I see is the following:

1. SDL_SemWaitTimeout calls sem_timedwait and sem_timedwait returns -1
2. errno is set to ETIMEDOUT (110)
3. SDL_SemWaitTimeout sets the SDL error to "Connection timed out"
4. SDL_SemWaitTimeout returns -1
5. My app interprets this as a failure instead of a timeout (and unfortunately my app doesn't handle this failure very gracefully :)

Looking at the documentation for sem_timedwait, it fails (-1) and sets errno=ETIMEDOUT if the timeout expires.

Assuming my analysis is correct, the attached patch should solve this problem.
Comment 1 Sam Lantinga 2012-02-20 20:52:20 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/c787fb1b5699