Wiki Page Content

Differences between revisions 6 and 7
Revision 6 as of 2011-02-14 20:17:50
Size: 1571
Editor: SheenaSmith
Comment: update content - 2/14 changeset 5295
Revision 7 as of 2011-02-27 16:12:14
Size: 1549
Editor: SheenaSmith
Comment: hide comments, notes
Deletions are marked like this. Additions are marked like this.
Line 32: Line 32:
<<Color2(green,Should this example be Included on the SDL_!DestroyCond page?)>>
/*
Should this example be Included on the SDL_!DestroyCond page? */
Line 57: Line 58:
<<Color2(green,Since this has no params does it actually ''create'' the structure or does it just assign an existing structure to a thread?)>> /* Since this has no params does it actually ''create'' the structure or does it just assign an existing structure to a thread? */

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);

*

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.


CategoryAPI, CategoryMutex

None: SDL_CreateCond (last edited 2014-01-11 13:50:10 by PhilippWiesemann)

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