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

Summary: Windows implementation of SDL Semaphores does not use atomic increment/decrement operations
Product: SDL Reporter: John Bartholomew <john.waffles>
Component: threadAssignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: HG 2.0   
Hardware: x86   
OS: Windows (All)   

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.