Wiki Page Content

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.


CategoryAPI, CategoryMutex

None: SDL_CreateMutex (last edited 2015-08-21 21:22:59 by PhilippWiesemann)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit