|
Size: 936
Comment: update content - pointers, structs
|
Size: 1571
Comment: update content - 2/14 changeset 5295
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 35: | Line 35: |
| ''You can add useful comments here'' | 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. |
DRAFT |
SDL_CreateCond
Use this function to create a condition variable.
Syntax
SDL_cond* SDL_CreateCond(void)
Return Value
Returns the condition variable that is created.
Code Examples
*
SDL_cond *cond;
cond=SDL_CreateCond();
.
.
/* Do stuff */
.
.
SDL_DestroyCond(cond);
*
green
Remarks
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.
green
