Wiki Page Content

Differences between revisions 10 and 11
Revision 10 as of 2013-10-04 13:35:26
Size: 977
Editor: urkle
Comment:
Revision 11 as of 2014-12-29 21:54:30
Size: 1131
Editor: ChrisBush
Comment: Per quick feedback, noted that it blocks and also that SDL_mutexes are reentrant
Deletions are marked like this. Additions are marked like this.
Line 40: Line 40:
''You can add useful comments here'' Calls to this function do not return immediately if the mutex is already locked by another thread. See [[SDL_TryLockMutex]] to attempt to lock without blocking.

SDL mutexes are reentrant.

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 this function do not return immediately if the mutex is already 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)

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