Wiki Page Content

Differences between revisions 3 and 4
Revision 3 as of 2013-10-04 13:34:35
Size: 775
Editor: urkle
Comment:
Revision 4 as of 2014-12-30 00:42:28
Size: 924
Editor: ChrisBush
Comment: Per quick feedback form, clarifying that this call is blocking
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
''You can add useful comments here'' Calls to this function will not return while the mutex is locked by another thread. See [[SDL_TryLockMutex]] to attempt to lock the mutex without blocking.

SDL mutexes are recursive.

SDL_LockMutex

Use this function to lock a mutex created with SDL_CreateMutex().

Syntax

int SDL_LockMutex(SDL_mutex* 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.

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 will not return while the mutex is locked by another thread. See SDL_TryLockMutex to attempt to lock the mutex without blocking.

SDL mutexes are recursive.


CategoryAPI, CategoryMutex

None: SDL_LockMutex (last edited 2015-01-02 21:12:35 by PhilippWiesemann)

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