feat: alternate syntax for threads
This commit is contained in:
parent
61db6ed694
commit
aa57bab764
6 changed files with 70 additions and 7 deletions
|
|
@ -1 +0,0 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
33
engine/tests/src/thread.cc
Normal file
33
engine/tests/src/thread.cc
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue