diff options
author | Sam Lantinga <slouken@libsdl.org> | 2011-01-27 10:40:17 -0800 |
---|---|---|
committer | Sam Lantinga <slouken@libsdl.org> | 2011-01-27 10:40:17 -0800 |
commit | 98d356be1b3a7a1d24f27f0f008b4b99bff215fc (patch) | |
tree | 2b0b83bfc5bbda5831ad83a0fbd31782e6bc5c79 /include/SDL_mutex.h | |
parent | 96fd668ed6b7af8e758af27e8c381b07443ccee2 (diff) |
Improved condition variable documentation
Diffstat (limited to 'include/SDL_mutex.h')
-rw-r--r-- | include/SDL_mutex.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/include/SDL_mutex.h b/include/SDL_mutex.h index e066f944b3..c117bdbccb 100644 --- a/include/SDL_mutex.h +++ b/include/SDL_mutex.h @@ -164,6 +164,31 @@ typedef struct SDL_cond SDL_cond; /** * Create a condition variable. + * + * Typical use of condition variables: + * + * Thread A: + * SDL_LockMutex(lock); + * while ( ! condition ) { + * SDL_CondWait(cond, lock); + * } + * SDL_UnlockMutex(lock); + * + * Thread B: + * SDL_LockMutex(lock); + * ... + * condition = true; + * ... + * SDL_CondSignal(cond); + * SDL_UnlockMutex(lock); + * + * There is some discussion whether to signal the condition variable + * with the mutex locked or not. There is some potential performance + * benefit to unlocking first on some platforms, but there are some + * potential race conditions depending on how your code is structured. + * + * In general it's safer to signal the condition variable while the + * mutex is locked. */ extern DECLSPEC SDL_cond *SDLCALL SDL_CreateCond(void); @@ -181,6 +206,7 @@ extern DECLSPEC int SDLCALL SDL_CondSignal(SDL_cond * cond); /** * Restart all threads that are waiting on the condition variable. + * * \return 0 or -1 on error. */ extern DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond * cond); |