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 668 - Windows implementation of SDL Semaphores does not use atomic increment/decrement operations
Summary: Windows implementation of SDL Semaphores does not use atomic increment/decrem...
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: thread (show other bugs)
Version: HG 2.0
Hardware: x86 Windows (All)
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-01-04 10:15 UTC by John Bartholomew
Modified: 2009-02-16 21:39 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Bartholomew 2009-01-04 10:15:52 UTC
The Windows semaphore implementation maintains its own count on top of the use of the normal Windows semaphore primitive.  This count is maintained in a non-threadsafe manner, being incremented and decremented with naked ops.
Fix by using InterlockedIncrement and InterlockedDecrement.  Can cause deadlocks (in, e.g., audio code)

NB: Already fixed in the 1.2 branch, just needs to be merged back to HEAD.  Relevant revision is r3470.

For history, see SDL mailing list archives:
http://lists.libsdl.org/pipermail/sdl-libsdl.org/2007-December/thread.html#63669
Thread "[SDL] SDL Semaphore implementation broken on Windows?"
Comment 1 Sam Lantinga 2009-02-16 21:39:52 UTC
Thanks, this is fixed in revision 4435.