OSDN Git Service

SDL_Rect サンプルコードを修正 コピー先のwとhは無視されるため0とした https://github.com/libsdl-org/sdlwiki/commit...
[sdl2referencejp/sdl2referencejp.git] / SDL_SemWait.html
index 0e9be86..c5da092 100644 (file)
@@ -1,78 +1,84 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\r
-<html lang="ja-JP">\r
-<head>\r
-<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">\r
-<meta http-equiv="Content-Style-Type" content="text/css">\r
-<meta name="keywords" content="Simple Directmedia Layer SDL2.0">\r
-<link rel="top" href="index.html" title="\83z\81[\83\80">\r
-<link rel="parent" href="CategoryMutex.html" title="1\82Â\8fã">\r
-<title>SDL_SemWait</title>\r
-</head>\r
-<body>\r
-<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\r
-<hr>\r
-<h1>SDL_SemWait</h1>\r
-\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
-<h2>\8d\\95¶</h2>\r
-<code>int SDL_SemWait(SDL_sem* sem)</code>\r
-<h2>\88ø\90\94</h2>\r
-<table border="1" summary="SDL_SemWait">\r
-<tr><td>sem</td><td>\83Z\83}\83t\83H</td></tr>\r
-</table>\r
-<h2>\96ß\82è\92l</h2>\r
-\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·.\r
-<a href="SDL_GetError.html">SDL_GetError()</a>\82Å\8fÚ\8d×\82ð\92m\82é\82±\82Æ\82ª\82Å\82«\82é.\r
-<h2>\83T\83\93\83v\83\8b\83R\81[\83h</h2>\r
-<p>\r
-<code>\r
-<pre>\r
-SDL_atomic_t done;\r
-SDL_sem *sem;\r
-\r
-SDL_AtomicSet(&amp;done, 0);\r
-sem = SDL_CreateSemaphore(0);\r
-.\r
-.\r
-Thread A:\r
-    while (!SDL_AtomicGet(&amp;done)) {\r
-        add_data_to_queue();\r
-        SDL_SemPost(sem);\r
-    }\r
-\r
-Thread B:\r
-    while (!SDL_AtomicGet(&amp;done)) {\r
-        SDL_SemWait(sem);\r
-        if (data_available()) {\r
-            get_data_from_queue();\r
-        }\r
-    }\r
-.\r
-.\r
-SDL_AtomicSet(&amp;done, 1);\r
-SDL_SemPost(sem);\r
-wait_for_threads();\r
-SDL_DestroySemaphore(sem);\r
-</pre>\r
-</code>\r
-</p>\r
-<h2>\8fÚ\8d×</h2>\r
-<p>\r
-\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é.\r
-\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
-</p>\r
-<p>\r
-\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é.\r
-</p>\r
-<h2>\8aÖ\98A\8d\80\96Ú(\8aÖ\90\94)</h2>\r
-<a href="SDL_CreateSemaphore.html">SDL_CreateSemaphore</a><br>\r
-<a href="SDL_DestroySemaphore.html">SDL_DestroySemaphore</a><br>\r
-<a href="SDL_SemPost.html">SDL_SemPost</a><br>\r
-<a href="SDL_SemTryWait.html">SDL_SemTryWait</a><br>\r
-<a href="SDL_SemValue.html">SDL_SemValue</a><br>\r
-<a href="SDL_SemWait.html">SDL_SemWait</a><br>\r
-<a href="SDL_SemWaitTimeout.html">SDL_SemWaitTimeout</a><br>\r
-<h2>SDL Wiki\82Ö\82Ì\83\8a\83\93\83N</h2>\r
-<a href="https://wiki.libsdl.org/SDL_SemWait">SDL_SemWait - SDL Wiki</a>\r
-<hr>\r
-</body>\r
-</html>\r
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html lang="ja-JP">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
+<meta http-equiv="Content-Style-Type" content="text/css">
+<meta name="keywords" content="Simple Directmedia Layer SDL2.0">
+<link rel="top" href="index.html" title="\83z\81[\83\80">
+<link rel="parent" href="CategoryMutex.html" title="1\82Â\8fã">
+<title>SDL_SemWait</title>
+</head>
+<body>
+<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
+<hr>
+<h1>SDL_SemWait</h1>
+\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é
+<h2>\8d\\95¶</h2>
+<code>int SDL_SemWait(SDL_sem* sem)</code>
+<h2>\88ø\90\94</h2>
+<table border="1" summary="SDL_SemWait">
+<tr><td>sem</td><td>\83Z\83}\83t\83H</td></tr>
+</table>
+<h2>\96ß\82è\92l</h2>
+\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·.
+<a href="SDL_GetError.html">SDL_GetError()</a>\82Å\8fÚ\8d×\82ð\92m\82é\82±\82Æ\82ª\82Å\82«\82é.
+<h2>\83T\83\93\83v\83\8b\83R\81[\83h</h2>
+<p>
+<code>
+<pre>
+#define NB_WAITER 10
+
+SDL_sem *sem;
+
+// 2\95b\82²\82Æ\82É\83Z\83}\83t\83H\82ð\89Á\8eZ\82·\82é
+int poster_thread() {
+  for (int i = 0; i < NB_WAITER; i++) {
+    SDL_SemPost(sem);
+    SDL_Delay(2 * 1000);
+  }
+  return 0;
+}
+
+int waiter_thread() {
+  int status;
+
+  status = SDL_SemWait(sem);
+  
+  if (status == 0) {
+    SDL_Log("\83Z\83}\83t\83H\82ð\8c¸\8eZ\82µ\82½\n");
+  } else {
+    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());
+  }
+  return 0;
+}
+
+int main() {
+  sem = SDL_CreateSemaphore(0);
+  create_and_wait_threads(); // \89Á\8eZ\83X\83\8c\83b\83h1\8cÂ, \8c¸\8eZ\83X\83\8c\83b\83h10\8cÂ
+  SDL_DestroySemaphore(sem);
+}
+</pre>
+</code>
+</p>
+<h2>\8fÚ\8d×</h2>
+<p>
+\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é.
+\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é.
+</p>
+<p>
+\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é.
+</p>
+<h2>\83o\81[\83W\83\87\83\93</h2>
+SDL 2.0.0\88È\8d~
+<h2>\8aÖ\98A\8d\80\96Ú(\8aÖ\90\94)</h2>
+<a href="SDL_CreateSemaphore.html">SDL_CreateSemaphore</a><br>
+<a href="SDL_DestroySemaphore.html">SDL_DestroySemaphore</a><br>
+<a href="SDL_SemPost.html">SDL_SemPost</a><br>
+<a href="SDL_SemTryWait.html">SDL_SemTryWait</a><br>
+<a href="SDL_SemValue.html">SDL_SemValue</a><br>
+<a href="SDL_SemWaitTimeout.html">SDL_SemWaitTimeout</a><br>
+<h2>SDL Wiki\82Ö\82Ì\83\8a\83\93\83N</h2>
+<a href="https://wiki.libsdl.org/SDL_SemWait">SDL_SemWait - SDL Wiki</a>
+<hr>
+</body>
+</html>