summaryrefslogtreecommitdiffstatshomepage
path: root/test
diff options
context:
space:
mode:
authorEgor Tensin <egor@tensin.name>2026-06-06 18:04:17 +0200
committerEgor Tensin <egor@tensin.name>2026-06-06 18:04:17 +0200
commitef0952fadae6794e225c0c1654887408bcadbf64 (patch)
tree4f1b53f7e757f175aa7d39de36083dd4155c9a71 /test
parentworkflows/test: reschedule for my convenience (diff)
downloadsetup-mingw-ef0952fadae6794e225c0c1654887408bcadbf64.tar.gz
setup-mingw-ef0952fadae6794e225c0c1654887408bcadbf64.zip
foo.cpp -> test/threads.cpp
Diffstat (limited to 'test')
-rw-r--r--test/threads.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/threads.cpp b/test/threads.cpp
new file mode 100644
index 0000000..a7891bb
--- /dev/null
+++ b/test/threads.cpp
@@ -0,0 +1,39 @@
+#include <array>
+#include <cstddef>
+#include <exception>
+#include <functional>
+#include <iostream>
+#include <mutex>
+#include <thread>
+
+namespace {
+
+struct Counter {
+ std::mutex mtx;
+ std::size_t impl = 0;
+};
+
+void do_something(Counter& counter) {
+ std::lock_guard<std::mutex> lck{counter.mtx};
+ ++counter.impl;
+ std::cout << "Doing something #" << counter.impl << '\n';
+}
+
+}
+
+int main() {
+ try {
+ Counter counter;
+ std::array<std::thread, 3> workers;
+ for (auto& worker : workers) {
+ worker = std::thread{&do_something, std::ref(counter)};
+ }
+ for (auto& worker : workers) {
+ worker.join();
+ }
+ } catch (const std::exception& e) {
+ std::cerr << e.what() << '\n';
+ return 1;
+ }
+ return 0;
+}