int SDL_SemTryWait(SDL_sem* sem)
sem | セマフォ |
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)) {
if (SDL_SemTryWait(sem) == 0 && data_available()) {
get_data_from_queue();
}
... ここで他の処理を行う
}
.
.
SDL_AtomicSet(&done, 1);
SDL_SemPost(sem);
wait_for_threads();
SDL_DestroySemaphore(sem);