|
Size: 1549
Comment: hide comments, notes
|
Size: 1151
Comment:
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 2: | Line 2: |
| #pragma disable-camelcase ||<tablewidth="100%" style="color: #FF0000;" :> DRAFT|| |
#pragma camelcase off |
| Line 16: | Line 15: |
| Returns ^the condition variable that is created^. | Returns a new condition variable or NULL on failure; call [[SDL_GetError]]() for more information. |
| Line 19: | Line 18: |
| * | ## Begin Condition Variable Example Typical use of condition variables: |
| Line 21: | Line 21: |
| SDL_bool condition = SDL_FALSE; SDL_mutex *lock; |
|
| Line 23: | Line 25: |
| cond=SDL_CreateCond(); | lock = SDL_CreateMutex(); cond = SDL_CreateCond(); |
| Line 26: | Line 29: |
| /* Do stuff */ . . SDL_DestroyCond(cond); }}} *<<BR>> /* Should this example be Included on the SDL_!DestroyCond page? */ == Remarks == Typical use of condition variables: {{{ |
|
| Line 40: | Line 31: |
| while ( ! condition ) { | while ( !condition ) { |
| Line 48: | Line 39: |
| condition = true; | condition = SDL_TRUE; |
| Line 52: | Line 43: |
| . . SDL_DestroyCond(cond); SDL_DestroyMutex(lock); |
|
| Line 53: | Line 48: |
| 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. | ## End Condition Variable Example |
| Line 55: | Line 50: |
| In general it's safer to signal the condition variable while the mutex is locked. /* Since this has no params does it actually ''create'' the structure or does it just assign an existing structure to a thread? */ |
== Remarks == ''You can add useful comments here'' |
| Line 61: | Line 54: |
| .[[SDL_CondSignal]] * .[[SDL_CondWait]] * .[[SDL_DestroyCond]] * |
.[[SDL_CondSignal]] .[[SDL_CondWait]] .[[SDL_DestroyCond]] |
SDL_CreateCond
Use this function to create a condition variable.
Syntax
SDL_cond* SDL_CreateCond(void)
Return Value
Returns a new condition variable or NULL on failure; call SDL_GetError() for more information.
Code Examples
Typical use of condition variables:
SDL_bool condition = SDL_FALSE;
SDL_mutex *lock;
SDL_cond *cond;
lock = SDL_CreateMutex();
cond = SDL_CreateCond();
.
.
Thread A:
SDL_LockMutex(lock);
while ( !condition ) {
SDL_CondWait(cond, lock);
}
SDL_UnlockMutex(lock);
Thread B:
SDL_LockMutex(lock);
...
condition = SDL_TRUE;
...
SDL_CondSignal(cond);
SDL_UnlockMutex(lock);
.
.
SDL_DestroyCond(cond);
SDL_DestroyMutex(lock);
Remarks
You can add useful comments here
