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 @@

–ß‚è’l

‘Ò‹@‘€ì‚ɐ¬Œ÷‚µ‚½‚Æ‚«0, ‘Ò‚¿ŽžŠÔ“à‚É‘Ò‹@‘€ì‚ɐ¬Œ÷‚µ‚È‚©‚Á‚½‚Æ‚«SDL_MUTEX_TIMEDOUT, Ž¸”s‚Ì‚Æ‚«•‰‚̐”‚̃Gƒ‰[ƒR[ƒh‚ð–ß‚·. SDL_GetError()‚ŏڍׂð’m‚邱‚Æ‚ª‚Å‚«‚é. +

ƒTƒ“ƒvƒ‹ƒR[ƒh

+

+ +

+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; /* 1•b‚²‚Æ‚É“®ì‚·‚é */
+
+    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ƒ}ƒtƒHsem‚Ì’l‚ª³‚É‚È‚é, Š„‚荞‚Ý‚ª”­¶‚·‚é, ƒGƒ‰[‚ª”­¶‚·‚é, ‚Ü‚½‚Í‘Ò‚¿ŽžŠÔ‚ªŒo‰ß‚·‚é‚Ü‚Å‚±‚̊֐”‚ðŒÄ‚ñ‚¾ƒXƒŒƒbƒh‚ð’âŽ~‚·‚é.