Wiki Page Content

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)

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