|
Size: 1116
Comment: Added missing (), see SGWikiBasics.
|
← Revision 14 as of 2015-08-21 21:22:59 ⇥
Size: 1122
Comment: Fixed Remark, a blocking SDL_CreateMutex() would make no sense.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 40: | Line 40: |
| Calls to this function will not return while the mutex is locked by another thread. See [[SDL_TryLockMutex]]() to attempt to lock without blocking. | 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_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.
