SDL Wiki
(This is the documentation for SDL3, which is under heavy development and the API is changing! SDL2 is the current stable version!)


Lock the mutex.


int SDL_LockMutex(SDL_Mutex *mutex) SDL_ACQUIRE(mutex);

Function Parameters

mutex the mutex to lock

Return Value

Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information.


This will block until the mutex is available, which is to say it is in the unlocked state and the OS has chosen the caller as the next thread to lock it. Of all threads waiting to lock the mutex, only one may do so at a time.

It is legal for the owning thread to lock an already-locked mutex. It must unlock it the same number of times before it is actually made available for other threads in the system (this is known as a "recursive mutex").


This function is available since SDL 3.0.0.

Code Examples

int status;
SDL_mutex *mutex;

mutex = SDL_CreateMutex();
if (!mutex) {
  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex\n");

status = SDL_LockMutex(mutex);

if (status == 0) {
  SDL_Log("Locked mutex\n");
} else {
  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock mutex\n");


CategoryAPI, CategoryMutex

[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.