Native condition variables on Windows

Windows natively supports proper condition variables since Windows Vista. Currently, SDL uses its own implementation with semaphores and mutexes.

Are there any plans to use Windows’ built-in functions instead?

SDL is a wrapper around an OSs native functions usually. Currently the Windows portion of SDL uses: InitializeCriticalSectionAndSpinCountand InitializeCriticalSectionEx for its mutexes and CreateSemaphore and CreateSemaphoreEx for its semaphores. So as far as I can tell, it already is using them.

It’s very nice that you try to answer basically all questions here, but could you please make sure that a) you read and understood the question thoroughly b) actually know the answer?

The question was not about how semaphores and mutexes are implemented, but about how condition variables are implemented - more specifically why they’re implemented with mutexes and semaphores when Windows offers native condition variables on Vista and newer…

I guess the answer is that when those were implemented Windows XP support still mattered. I can imagine that for some people it still does, so unless the native condition variables have big advantages over the custom ones in SDL, it probably makes sense to just keep the custom implementation and not break XP compatibility.

1 Like

I’ve been thinking the same, but didn’t want to hurt his feelings. :roll_eyes:

If it’s for the purposes of Windows XP support, that’s fair enough.

Still, threading primitives may seem simple, but especially condition variables are anything but that. As far as I can tell the current implementation is solid (handles a few edge cases correctly which I’ve run into problems with in the past with other implementations). But still it’s not code I’d want to have to maintain in my codebase if I could help it. The native implementation might also be marginally faster, but that’s probaly irrelevant.