SDL_CreateMutex
Use this function to create a new mutex.
Syntax
SDL_mutex* SDL_CreateMutex(void)
Return Value
Returns the initialized and unlocked mutex or NULL on failure; call SDL_GetError() for more information.
Code Examples
SDL_mutex *mutex;
mutex = SDL_CreateMutex();
if (!mutex) {
fprintf(stderr, "Couldn't create mutex\n");
return;
}
if (SDL_LockMutex(mutex) == 0) {
/* Do stuff while mutex is locked */
SDL_UnlockMutex(mutex);
} else {
fprintf(stderr, "Couldn't lock mutex\n");
}
SDL_DestroyMutex(mutex);
Remarks
Calls to SDL_LockMutex() will not return while the mutex is locked by another thread. See SDL_TryLockMutex() to attempt to lock without blocking.
SDL mutexes are reentrant.