OSDN Git Service

SDL_atomic_t サンプルコードを修正 https://wiki.libsdl.org/SDL_atomic_t?action=diff&rev1=3&rev2=4
[sdl2referencejp/sdl2referencejp.git] / SDL_SemWaitTimeout.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r
2 <html lang="ja-JP">\r
3 <head>\r
4 <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">\r
5 <meta http-equiv="Content-Style-Type" content="text/css">\r
6 <meta name="keywords" content="Simple Directmedia Layer SDL2.0">\r
7 <link rel="top" href="index.html" title="\83z\81[\83\80">\r
8 <link rel="parent" href="CategoryMutex.html" title="1\82Â\8fã">\r
9 <title>SDL_SemWaitTimeout</title>\r
10 </head>\r
11 <body>\r
12 <a href="index.html">\96Ú\8e\9f</a> - <a href="ApiByCategory.html">API(\8b@\94\\95Ê)</a> - <a href="CategoryMutex.html">\93¯\8aú\83v\83\8a\83~\83e\83B\83u</a> - SDL_SemWaitTimeout\r
13 <hr>\r
14 <h1>SDL_SemWaitTimeout</h1>\r
15 \83Z\83}\83t\83H\82Ì\92l\82ª\90³\82É\82È\82é\82Ü\82Å\91Ò\8b@\82µ, \83Z\83}\83t\83H\82Ì\92l\82ð\8c¸\8eZ\82·\82é\r
16 <h2>\8d\\95¶</h2>\r
17 <code>int SDL_SemWaitTimeout(SDL_sem* sem, Uint32 ms)</code>\r
18 <h2>\88ø\90\94</h2>\r
19 <table border="1" summary="SDL_SemWaitTimeout">\r
20 <tr><td>sem</td><td>\83Z\83}\83t\83H</td></tr>\r
21 <tr><td>ms</td><td>\83~\83\8a\95b\92P\88Ê\82Ì\91Ò\82¿\8e\9e\8aÔ</td></tr>\r
22 </table>\r
23 <h2>\96ß\82è\92l</h2>\r
24 \91Ò\8b@\91\80\8dì\82É\90¬\8c÷\82µ\82½\82Æ\82«0, \91Ò\82¿\8e\9e\8aÔ\93à\82É\91Ò\8b@\91\80\8dì\82É\90¬\8c÷\82µ\82È\82©\82Á\82½\82Æ\82«SDL_MUTEX_TIMEDOUT, \8e¸\94s\82Ì\82Æ\82«\95\89\82Ì\90\94\82Ì\83G\83\89\81[\83R\81[\83h\82ð\96ß\82·.\r
25 <a href="SDL_GetError.html">SDL_GetError()</a>\82Å\8fÚ\8d×\82ð\92m\82é\82±\82Æ\82ª\82Å\82«\82é.\r
26 <h2>\83T\83\93\83v\83\8b\83R\81[\83h</h2>\r
27 <p>\r
28 <code>\r
29 <pre>\r
30 SDL_atomic_t done;\r
31 SDL_sem *sem;\r
32 \r
33 SDL_AtomicSet(&amp;done, 0);\r
34 sem = SDL_CreateSemaphore(0);\r
35 .\r
36 .\r
37 Thread A:\r
38     while (!SDL_AtomicGet(&amp;done)) {\r
39         add_data_to_queue();\r
40         SDL_SemPost(sem);\r
41     }\r
42 \r
43 Thread B:\r
44     const Uint32 timeout = 1000; /* 1\95b\82²\82Æ\82É\93®\8dì\82·\82é */\r
45 \r
46     while (!SDL_AtomicGet(&amp;done)) {\r
47         if (SDL_SemWaitTimeout(sem, timeout) == 0 &amp;&amp; data_available()) {\r
48             get_data_from_queue();\r
49         }\r
50         ... \82±\82±\82Å\91¼\82Ì\8f\88\97\9d\82ð\8ds\82¤\r
51     }\r
52 .\r
53 .\r
54 SDL_AtomicSet(&amp;done, 1);\r
55 SDL_SemPost(sem);\r
56 wait_for_threads();\r
57 SDL_DestroySemaphore(sem);\r
58 </pre>\r
59 </code>\r
60 </p>\r
61 <h2>\8fÚ\8d×</h2>\r
62 <p>\r
63 \83Z\83}\83t\83Hsem\82Ì\92l\82ª\90³\82É\82È\82é, \8a\84\82è\8d\9e\82Ý\82ª\94­\90\82·\82é, \83G\83\89\81[\82ª\94­\90\82·\82é, \82Ü\82½\82Í\91Ò\82¿\8e\9e\8aÔ\82ª\8co\89ß\82·\82é\82Ü\82Å\82±\82Ì\8aÖ\90\94\82ð\8cÄ\82ñ\82¾\83X\83\8c\83b\83h\82ð\92â\8e~\82·\82é.\r
64 \8cÄ\82Ñ\8fo\82µ\82ª\90¬\8c÷\82·\82ê\82Î, \83Z\83}\83t\83H\82Ì\92l\82ð\83A\83g\83~\83b\83N\82É\8c¸\8eZ\82·\82é.\r
65 </p>\r
66 <h2>\8aÖ\98A\8d\80\96Ú(\8aÖ\90\94)</h2>\r
67 <a href="SDL_CreateSemaphore.html">SDL_CreateSemaphore</a><br>\r
68 <a href="SDL_DestroySemaphore.html">SDL_DestroySemaphore</a><br>\r
69 <a href="SDL_SemPost.html">SDL_SemPost</a><br>\r
70 <a href="SDL_SemTryWait.html">SDL_SemTryWait</a><br>\r
71 <a href="SDL_SemValue.html">SDL_SemValue</a><br>\r
72 <a href="SDL_SemWait.html">SDL_SemWait</a><br>\r
73 <h2>SDL Wiki\82Ö\82Ì\83\8a\83\93\83N</h2>\r
74 <a href="https://wiki.libsdl.org/SDL_SemWaitTimeout">SDL_SemWaitTimeout - SDL Wiki</a>\r
75 <hr>\r
76 </body>\r
77 </html>\r