No description
Find a file
Sam Lantinga 605f1db186 Date: Thu, 27 Dec 2007 07:38:25 +0000
From: John Bartholomew
Subject: [SDL] SDL Semaphore implementation broken on Windows?
Hi,

Over the past couple of days, I've been battling with SDL, SDL_Mixer and SMPEG to try to find an audio hang bug.  I believe I've found the problem, which I think is a race condition inside SDL's semaphore implementation (at least the Windows implementation).  The semaphore code uses Windows' built in semaphore functions, but it also maintains a separate count value.  This count value is updated with bare increment and decrement operations in SemPost and SemWaitTimeout - no locking primitives to protect them.

In tracking down the apparent audio bug, I found that at some point a semaphore's count value was being decremented to -1, which is clearly not a valid value for it to take.

I'm still not certain exactly what sequence of operations is occuring for this to happen, but I believe that overall it's a race condition between a thread calling SemPost (which increments the count) and the thread on the other end calling SemWait (which decrements it).

I will try to make a test case to verify this, but I'm not sure if I'll be able to   (threading errors being difficult to reproduce even in the best    circumstances).

However, assuming this is the cause of my problems, there is a very
simple fix:
Windows provides InterlockedIncrement() and InterlockedDecrement()
functions to perform increments and decrements which are guaranteed to be atomic.  So the fix is in thread/win32/SDL_syssem.c: replace occurrences of --sem->count with InterlockedDecrement(&sem->count); and replace occurrences of ++sem->count with InterlockedIncrement(&sem->count);

This is using SDL v1.2.12, built with VC++ 2008 Express, running on a
Core 2 duo processor.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403535
2009-02-17 05:39:18 +00:00
build-scripts Updated for older versions of subversion 2009-01-19 07:35:52 +00:00
docs Merged revision 3472 from SDL 1.2, fixing bug #493 2007-12-29 03:25:11 +00:00
include Fixed bug #537 2009-02-17 04:57:39 +00:00
src Date: Thu, 27 Dec 2007 07:38:25 +0000 2009-02-17 05:39:18 +00:00
test More of the same 2009-02-09 06:42:38 +00:00
VisualC Added testdraw2 to Visual C++ tests 2008-12-31 07:35:55 +00:00
VisualCE Unpacked project archives to get individual file history in subversion 2007-07-21 17:09:01 +00:00
Xcode Updated project with new source files 2008-12-25 04:56:44 +00:00
XCodeiPhoneOS Don't check in personal files 2009-01-02 01:32:51 +00:00
.indent.pro SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00
acinclude.m4 Fixed Visual C++ release build for Visual C++ 2005 2009-01-10 18:32:24 +00:00
autogen.sh Added yet another variant of autoconf to the list 2006-05-15 06:30:38 +00:00
Borland.html
Borland.zip
BUGS Merged r2977:2978 from branches/SDL-1.2: BUGS file cutdown. 2007-02-14 10:41:55 +00:00
configure.in More Mac OS X 10.3.9 fixes 2009-01-19 15:58:57 +00:00
COPYING This library is now available under the LGPL 2.1, the major change of which 2006-01-30 14:27:56 +00:00
CREDITS Fixed OpenGL state issue reported by Dmytro Bogovych 2009-01-14 06:53:03 +00:00
docs.html SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00
INSTALL
Makefile.dc SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00
Makefile.ds Initial work for NDS haptic support. 2008-09-06 00:10:16 +00:00
Makefile.in Fixed snapshot target 2009-01-12 06:22:26 +00:00
Makefile.minimal Final merge of Google Summer of Code 2008 work... 2008-08-25 09:55:03 +00:00
NOTES Added notes on the next steps for SDL 1.3 2007-08-16 21:43:19 +00:00
README Removed AmigaOS code for 1.3 branch. 2006-10-29 04:09:17 +00:00
README-SDL.txt
README.BeOS Added a reminder on where to put libSDL.so 2006-02-18 07:21:42 +00:00
README.CVS Info on Subversion repository access. 2006-04-26 23:17:39 +00:00
README.DC *** empty log message *** 2006-03-02 13:26:24 +00:00
README.DirectFB DirectFB cleanups & simple window manager 2009-01-11 23:49:23 +00:00
README.iphoneos Final merge of Google Summer of Code 2008 work... 2008-10-04 06:46:59 +00:00
README.MacOSX Added information about gcc-fat.sh to README.MacOSX 2006-05-16 07:26:48 +00:00
README.MiNT Add teamtap support 2006-09-16 17:13:41 +00:00
README.NanoX
README.OS2 SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00
README.Porting Added the dummy audio driver to instructions 2006-07-26 03:57:45 +00:00
README.QNX
README.RISCOS Update from Alan Buckley 2006-02-06 08:47:44 +00:00
README.SVN Testing Subversion commit RSS feed. 2008-07-05 18:25:28 +00:00
README.Watcom ------- Comment #5 From Marc Peter 2006-06-25 18:03 [reply] ------- 2006-06-26 01:33:53 +00:00
README.WinCE Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode, 2006-01-19 08:43:00 +00:00
README.wscons To: sdl@libsdl.org 2005-11-22 15:19:50 +00:00
sdl-config.in Merged r3002:3003 from branches/SDL-1.2: libdir fix in sdl-config and SDL.spec 2007-04-01 03:28:36 +00:00
sdl.m4 Merged fix for bug #542 from SDL 1.2 2008-01-24 15:51:52 +00:00
sdl.pc.in Merged fix for bug #531 from SDL 1.2 revision 3511 2008-01-01 15:26:11 +00:00
SDL.qpg.in Date: Fri, 18 Feb 2005 07:58:00 +0200 2006-01-29 09:19:55 +00:00
SDL.spec.in Merged r3002:3003 from branches/SDL-1.2: libdir fix in sdl-config and SDL.spec 2007-04-01 03:28:36 +00:00
TODO Added reminder for shaped windows 2009-02-14 15:56:26 +00:00
UNDER_CONSTRUCTION.txt SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00
VisualC.html Removed newline, to make sure revision control post-commit hook is working. 2008-12-01 09:45:01 +00:00
Watcom-OS2.zip SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00
Watcom-Win32.zip ------- Comment #5 From Marc Peter 2006-06-25 18:03 [reply] ------- 2006-06-26 01:33:53 +00:00
WhatsNew SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head. 2006-07-10 21:04:37 +00:00

                         Simple DirectMedia Layer

                                  (SDL)

                                Version 1.2

---
http://www.libsdl.org/

This is the Simple DirectMedia Layer, a general API that provides low
level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL,
and 2D framebuffer across multiple platforms.

The current version supports Linux, Windows, Windows CE, BeOS, MacOS,
Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX.
The code contains support for Dreamcast, Atari, AIX, OSF/Tru64,
RISC OS, SymbianOS, and OS/2, but these are not officially supported.

SDL is written in C, but works with C++ natively, and has bindings to
several other languages, including Ada, C#, Eiffel, Erlang, Euphoria,
Guile, Haskell, Java, Lisp, Lua, ML, Objective C, Pascal, Perl, PHP,
Pike, Pliant, Python, Ruby, and Smalltalk.

This library is distributed under GNU LGPL version 2, which can be
found in the file  "COPYING".  This license allows you to use SDL
freely in commercial programs as long as you link with the dynamic
library.

The best way to learn how to use SDL is to check out the header files in
the "include" subdirectory and the programs in the "test" subdirectory.
The header files and test programs are well commented and always up to date.
More documentation is available in HTML format in "docs/index.html", and
a documentation wiki is available online at:
	http://www.libsdl.org/cgi/docwiki.cgi

The test programs in the "test" subdirectory are in the public domain.

Frequently asked questions are answered online:
	http://www.libsdl.org/faq.php

If you need help with the library, or just want to discuss SDL related
issues, you can join the developers mailing list:
	http://www.libsdl.org/mailing-list.php

Enjoy!
	Sam Lantinga				(slouken@libsdl.org)