[SDL] SDL Semaphore implementation broken on Windows?
william at exoide.com
Fri Dec 28 15:11:49 PST 2007
Hi, here are my 2 cents,
x86 ASM INC and DEC are only atomic on mono-x86, if they are used on
An alternative (very x86 specific) would be "__asm LOCK INC DWORD PTR
provided that the memory is aligned on 32 bits boundary.
Anyway, one has to use the InterlockedXXXXX functions under Windows if
he wants to provide guaranteed atomic operation on any system running
Windows, ( XBox 360 included ) without assembly langage and cpu-specific
Sam Lantinga a écrit :
>> 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
> I'm pretty sure the 32-bit ++ and -- operators are atomic on x86 architectures.
> Are you sure this fixes the problem?
> -Sam Lantinga, Lead Software Engineer, Blizzard Entertainment
> SDL mailing list
> SDL at lists.libsdl.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL