Wiki Page Content

Differences between revisions 4 and 5
Revision 4 as of 2010-10-18 02:21:16
Size: 801
Editor: SheenaSmith
Comment: update content - pointers, structs
Revision 5 as of 2013-08-12 05:44:22
Size: 733
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 16: Line 15:
||'''sem'''||^the semaphore to destroy^|| ||'''sem'''||the semaphore to destroy||
Line 19: Line 18:
{{{#!highlight cpp
if (my_sem != NULL) {
        SDL_DestroySemaphore(my_sem);
        my_sem = NULL;
}
}}}
<<Include(SDL_CreateSemaphore, , , from="## Begin Semaphore Example", to="## End Semaphore Example")>>
Line 27: Line 21:
*<<BR>>It is not safe to destroy a semaphore if there are threads currently ,,blocked,, waiting on it. <<BR>>* It is not safe to destroy a semaphore if there are threads currently waiting on it.
Line 30: Line 24:
 .[[SDL_CreateSemaphore]] *

<<Color2(green,The old wiki lists the other Sem functions as RFs.)>>
 .[[SDL_CreateSemaphore]]
 .[[SDL_SemPost]]
 .[[SDL_SemTryWait]]
 .[[SDL_SemValue]]
 .[[SDL_SemWait]]
 .[[SDL_SemWaitTimeout]]

SDL_DestroySemaphore

Use this function to destroy a semaphore.

Syntax

void SDL_DestroySemaphore(SDL_sem* sem)

Function Parameters

sem

the semaphore to destroy

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

It is not safe to destroy a semaphore if there are threads currently waiting on it.


CategoryAPI, CategoryMutex

None: SDL_DestroySemaphore (last edited 2013-08-12 05:44:22 by Sam Lantinga)

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