X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=SDL_SemWaitTimeout.html;h=75896f0e4c0bd4394db4b9d68738cc98cb971d22;hb=9431271932847603881d2254d9dfa13b7b39048c;hp=b4206d5fe0e64ab55bf86bb13097754d1f57baf0;hpb=f2cb88399edce8fa68b178bf0cd2663d9d4ccd92;p=sdl2referencejp%2Fsdl2referencejp.git diff --git a/SDL_SemWaitTimeout.html b/SDL_SemWaitTimeout.html index b4206d5..75896f0 100644 --- a/SDL_SemWaitTimeout.html +++ b/SDL_SemWaitTimeout.html @@ -23,6 +23,41 @@
+
+
+
+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:
+ const Uint32 timeout = 1000; /* 1b²ÆÉ®ì·é */
+
+ while (!SDL_AtomicGet(&done)) {
+ if (SDL_SemWaitTimeout(sem, timeout) == 0 && data_available()) {
+ get_data_from_queue();
+ }
+ ... ±±Å¼Ìðs¤
+ }
+.
+.
+SDL_AtomicSet(&done, 1);
+SDL_SemPost(sem);
+wait_for_threads();
+SDL_DestroySemaphore(sem);
+
+
Z}tHsemÌlª³ÉÈé, èݪ¶·é, G[ª¶·é, ܽÍÒ¿Ôªoß·éÜűÌÖðÄñ¾Xbhðâ~·é.