|
20 | 20 |
|
21 | 21 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
22 | 22 | <meta name="keywords" content=" |
23 | | - C++,標準ライブラリ,リファレンス,ドキュメント,STL,std,cpp11 |
| 23 | + C++,標準ライブラリ,リファレンス,ドキュメント,STL,std,cpp11,thread_local |
24 | 24 | "> |
25 | 25 | <meta name="title" content="スレッドローカルストレージ [N2659] - cpprefjp C++日本語リファレンス" /> |
26 | 26 | <meta itemprop="name" content="スレッドローカルストレージ [N2659] - cpprefjp C++日本語リファレンス" /> |
|
68 | 68 |
|
69 | 69 | </head> |
70 | 70 | <body> |
71 | | -<header data-kunai-mdinfo="{"meta": {"cpp": ["cpp11"]}, "sources": [{"id": "2a4599bfd3c0907e015d1b59d19a455faf2a9777", "source": "#include <iostream>\n#include <thread>\n#include <random>\n#include <cstdint>\n\n// \u7bc4\u56f2[min_inclusive, max_inclusive]\u3067\u30e9\u30f3\u30c0\u30e0\u4e00\u69d8\u5206\u5e03\u3059\u308b\u6574\u6570\u3092\u751f\u6210\u3059\u308b\u3002\n// \u30b9\u30ec\u30c3\u30c9\u3054\u3068\u306b\u4e71\u6570\u306e\u72b6\u614b\u3092\u6301\u3064\u3002\nint random_range(int min_inclusive, int max_inclusive)\n{\n std::random_device seed_gen;\n std::uint32_t seed = seed_gen();\n thread_local std::mt19937 engine(seed);\n std::uniform_int_distribution<int> dist(min_inclusive, max_inclusive);\n return dist(engine);\n}\n\nint main()\n{\n // \u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u4e26\u884c\u306brandom_range()\u95a2\u6570\u3092\u547c\u3073\u51fa\u305b\u308b\n std::thread t1([]{\n int random_value = random_range(0, 100);\n\n // \u203bcout\u306b\u5bfe\u3059\u308b\u4e00\u5ea6\u306e\u66f8\u304d\u8fbc\u307f\u306f\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3067\u3042\u308b\u305f\u3081\u30013\u3064\u306e\u66f8\u304d\u8fbc\u307f\u30921\u3064\u306b\u7d71\u5408\u3002\n std::cout << \"thread1 : \" + std::to_string(random_value) + \"\\n\";\n });\n\n std::thread t2([]{\n int random_value = random_range(0, 100);\n std::cout << \"thread2 : \" + std::to_string(random_value) + \"\\n\";\n });\n\n t1.join();\n t2.join();\n}\n"}], "page_id": ["lang", "cpp11", "thread_local_storage"]}"> |
| 71 | +<header data-kunai-mdinfo="{"meta": {"cpp": ["cpp11"], "alias": ["thread_local"]}, "sources": [{"id": "2a4599bfd3c0907e015d1b59d19a455faf2a9777", "source": "#include <iostream>\n#include <thread>\n#include <random>\n#include <cstdint>\n\n// \u7bc4\u56f2[min_inclusive, max_inclusive]\u3067\u30e9\u30f3\u30c0\u30e0\u4e00\u69d8\u5206\u5e03\u3059\u308b\u6574\u6570\u3092\u751f\u6210\u3059\u308b\u3002\n// \u30b9\u30ec\u30c3\u30c9\u3054\u3068\u306b\u4e71\u6570\u306e\u72b6\u614b\u3092\u6301\u3064\u3002\nint random_range(int min_inclusive, int max_inclusive)\n{\n std::random_device seed_gen;\n std::uint32_t seed = seed_gen();\n thread_local std::mt19937 engine(seed);\n std::uniform_int_distribution<int> dist(min_inclusive, max_inclusive);\n return dist(engine);\n}\n\nint main()\n{\n // \u8907\u6570\u306e\u30b9\u30ec\u30c3\u30c9\u304b\u3089\u4e26\u884c\u306brandom_range()\u95a2\u6570\u3092\u547c\u3073\u51fa\u305b\u308b\n std::thread t1([]{\n int random_value = random_range(0, 100);\n\n // \u203bcout\u306b\u5bfe\u3059\u308b\u4e00\u5ea6\u306e\u66f8\u304d\u8fbc\u307f\u306f\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3067\u3042\u308b\u305f\u3081\u30013\u3064\u306e\u66f8\u304d\u8fbc\u307f\u30921\u3064\u306b\u7d71\u5408\u3002\n std::cout << \"thread1 : \" + std::to_string(random_value) + \"\\n\";\n });\n\n std::thread t2([]{\n int random_value = random_range(0, 100);\n std::cout << \"thread2 : \" + std::to_string(random_value) + \"\\n\";\n });\n\n t1.join();\n t2.join();\n}\n"}], "page_id": ["lang", "cpp11", "thread_local_storage"]}"> |
72 | 72 | <nav class="navbar navbar-default" role="navigation"> |
73 | 73 | <div class="container-fluid"> |
74 | 74 | <div class="navbar-header"> |
|
188 | 188 |
|
189 | 189 | <p class="text-right"><small> |
190 | 190 | 最終更新日時(UTC): |
191 | | - <span itemprop="datePublished" content="2025-10-22T16:15:43"> |
192 | | - 2025年10月22日 16時15分43秒 |
| 191 | + <span itemprop="datePublished" content="2026-01-16T17:13:36"> |
| 192 | + 2026年01月16日 17時13分36秒 |
193 | 193 | </span> |
194 | 194 | <br/> |
195 | 195 | <span itemprop="author" itemscope itemtype="http://schema.org/Person"> |
196 | | - <span itemprop="name">Akira Takahashi</span> |
| 196 | + <span itemprop="name">yoh</span> |
197 | 197 | </span> |
198 | 198 | が更新 |
199 | 199 | </small></p> |
|
214 | 214 |
|
215 | 215 | <h1 itemprop="name"><span class="token">スレッドローカルストレージ [N2659]</span><span class="cpp cpp11" title="C++11で追加">(C++11)</span></h1> |
216 | 216 | <div itemprop="articleBody"><p></p> |
| 217 | +<p></p> |
217 | 218 | <p>このページはC++11に採用された言語機能の変更を解説しています。</p> |
218 | 219 | <p>のちのC++規格でさらに変更される場合があるため<a href="#relative-page">関連項目</a>を参照してください。</p> |
219 | 220 | <p></p> |
|
0 commit comments