OSDN Git Service

API一覧に概要を追加 リンクを修正
[sdl2referencejp/sdl2referencejp.git] / SDL_SemWait.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html lang="ja-JP">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <meta name="keywords" content="Simple Directmedia Layer SDL2.0">
7 <link rel="top" href="index.html" title="\83z\81[\83\80">
8 <link rel="parent" href="CategoryMutex.html" title="1\82Â\8fã">
9 <title>SDL_SemWait</title>
10 </head>
11 <body>
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_SemWait
13 <hr>
14 <h1>SDL_SemWait</h1>
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é
16 <h2>\8d\\95¶</h2>
17 <code>int SDL_SemWait(SDL_sem* sem)</code>
18 <h2>\88ø\90\94</h2>
19 <table border="1" summary="SDL_SemWait">
20 <tr><td>sem</td><td>\83Z\83}\83t\83H</td></tr>
21 </table>
22 <h2>\96ß\82è\92l</h2>
23 \90¬\8c÷\82Ì\82Æ\82«0, \8e¸\94s\82Ì\82Æ\82«\95\89\82Ì\90\94\82Ì\83G\83\89\81[\83R\81[\83h\82ð\96ß\82·.
24 <a href="SDL_GetError.html">SDL_GetError()</a>\82Å\8fÚ\8d×\82ð\92m\82é\82±\82Æ\82ª\82Å\82«\82é.
25 <h2>\83T\83\93\83v\83\8b\83R\81[\83h</h2>
26 <p>
27 <code>
28 <pre>
29 #define NB_WAITER 10
30
31 SDL_sem *sem;
32
33 // 2\95b\82²\82Æ\82É\83Z\83}\83t\83H\82ð\89Á\8eZ\82·\82é
34 int poster_thread() {
35   for (int i = 0; i < NB_WAITER; i++) {
36     SDL_SemPost(sem);
37     SDL_Delay(2 * 1000);
38   }
39   return 0;
40 }
41
42 int waiter_thread() {
43   int status;
44
45   status = SDL_SemWait(sem);
46   
47   if (status == 0) {
48     SDL_Log("\83Z\83}\83t\83H\82ð\8c¸\8eZ\82µ\82½\n");
49   } else {
50     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\91Ò\82Á\82Ä\82¢\82é\8aÔ\82É\83G\83\89\81[\82ª\94­\90\82µ\82½: %s\n", SDL_GetError());
51   }
52   return 0;
53 }
54
55 int main() {
56   sem = SDL_CreateSemaphore(0);
57   create_and_wait_threads(); // \89Á\8eZ\83X\83\8c\83b\83h1\8cÂ, \8c¸\8eZ\83X\83\8c\83b\83h10\8cÂ
58   SDL_DestroySemaphore(sem);
59 }
60 </pre>
61 </code>
62 </p>
63 <h2>\8fÚ\8d×</h2>
64 <p>
65 \83Z\83}\83t\83Hsem\82Ì\92l\82ª\90³\82É\82È\82é, \8a\84\82è\8d\9e\82Ý\82ª\94­\90\82·\82é, \82Ü\82½\82Í\83G\83\89\81[\82ª\94­\90\82·\82é\82Ü\82Å\82±\82Ì\8aÖ\90\94\82ð\8cÄ\82ñ\82¾\83X\83\8c\83b\83h\82ð\92â\8e~\82·\82é.
66 \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é.
67 </p>
68 <p>
69 \82±\82Ì\8aÖ\90\94\82Í, <a href="SDL_SemWaitTimeout.html">SDL_SemWaitTimeout()</a>\82Ì\91Ò\82¿\8e\9e\8aÔ\82ðSDL_MUTEX_MAXWAIT\82Æ\82µ\82½\82Ì\82Æ\93¯\82\82Å\82 \82é.
70 </p>
71 <h2>\83o\81[\83W\83\87\83\93</h2>
72 SDL 2.0.0\88È\8d~
73 <h2>\8aÖ\98A\8d\80\96Ú(\8aÖ\90\94)</h2>
74 <a href="SDL_CreateSemaphore.html">SDL_CreateSemaphore</a><br>
75 <a href="SDL_DestroySemaphore.html">SDL_DestroySemaphore</a><br>
76 <a href="SDL_SemPost.html">SDL_SemPost</a><br>
77 <a href="SDL_SemTryWait.html">SDL_SemTryWait</a><br>
78 <a href="SDL_SemValue.html">SDL_SemValue</a><br>
79 <a href="SDL_SemWaitTimeout.html">SDL_SemWaitTimeout</a><br>
80 <h2>SDL Wiki\82Ö\82Ì\83\8a\83\93\83N</h2>
81 <a href="https://wiki.libsdl.org/SDL_SemWait">SDL_SemWait - SDL Wiki</a>
82 <hr>
83 </body>
84 </html>