feat: alternate syntax for threads

This commit is contained in:
maelstrom 2026-05-28 18:04:14 +02:00
commit aa57bab764
6 changed files with 70 additions and 7 deletions

View file

@ -1 +0,0 @@
#include <catch2/catch_test_macros.hpp>

View file

@ -0,0 +1,33 @@
#include "fishbone/thread.h"
#include <catch2/catch_test_macros.hpp>
struct thread_arg {
int& a;
};
TEST_CASE("Thread") {
int a = 0;
fishbone::Thread th([&a](auto) {
for (int i = 0; i < 100; i++) {
a++;
}
});
th.join();
REQUIRE(a == 100);
a = 0;
thread_arg arg { a };
fishbone::Thread th2([](auto, void* data) {
thread_arg& arg = *static_cast<thread_arg*>(data);
for (int i = 0; i < 100; i++) {
arg.a++;
}
}, &arg);
th.join();
REQUIRE(a == 100);
}