Wiki Page Content

Differences between revisions 1 and 7 (spanning 6 versions)
Revision 1 as of 2010-06-02 01:27:33
Size: 747
Editor: SheenaSmith
Comment: create page, add content (Wed Mar 10 ver; changeset 4428)
Revision 7 as of 2013-08-12 05:48:11
Size: 852
Editor: Sam Lantinga
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 6: Line 5:
Use this function to atomically (?? automatically ??) increase the semaphore's count (not blocking). Use this function to atomically increment a semaphore's value and wake waiting threads.
Line 16: Line 15:
||'''sem'''||^a pointer to the SDL_sem structure to be affected^|| ||'''sem'''||the semaphore to increment||
Line 19: Line 18:
Returns 0 on success, or -1 on failure; call [[SDL_GetError]]() for more information. Returns 0 on success or a negative error code on failure ; call [[SDL_GetError]]() for more information.
Line 22: Line 21:
{{{#!highlight cpp
You can add your code example here
}}}
<<Include(SDL_CreateSemaphore, , , from="## Begin Semaphore Example", to="## End Semaphore Example")>>
Line 30: Line 27:
 .[[SDL_CreateSemaphore]]
 .[[SDL_DestroySemaphore]]
 .[[SDL_SemTryWait]]
 .[[SDL_SemValue]]
 .[[SDL_SemWait]]
 .[[SDL_SemWaitTimeout]]

SDL_SemPost

Use this function to atomically increment a semaphore's value and wake waiting threads.

Syntax

int SDL_SemPost(SDL_sem* sem)

Function Parameters

sem

the semaphore to increment

Return Value

Returns 0 on success or a negative error code on failure ; call SDL_GetError() for more information.

Code Examples

Typical use of semaphores:

SDL_atomic_t done;
SDL_sem *sem;

SDL_AtomicSet(&done, 0);
sem = SDL_CreateSemaphore(0);
.
.
Thread A:
    while (!SDL_AtomicGet(&done)) {
        add_data_to_queue();
        SDL_SemPost(sem);
    }

Thread B:
    while (!SDL_AtomicGet(&done)) {
        SDL_SemWait(sem);
        if (data_available()) {
            get_data_from_queue();
        }
    }
.
.
SDL_AtomicSet(&done, 1);
SDL_SemPost(sem);
wait_for_threads();
SDL_DestroySemaphore(sem);

Remarks

You can add useful comments here


CategoryAPI, CategoryMutex

None: SDL_SemPost (last edited 2013-08-12 05:48:11 by Sam Lantinga)

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