MCPcopy Create free account
hub / github.com/FastLED/FastLED / FL_TEST_FILE

Function FL_TEST_FILE

tests/fl/stl/thread.cpp:11–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#include "platforms/stub/mutex_stub_stl.h"
10
11FL_TEST_FILE(FL_FILEPATH) {
12
13FL_TEST_CASE("fl::thread - basic construction and joinable") {
14 // Default constructed thread is not joinable
15 fl::thread t1;
16 FL_REQUIRE(!t1.joinable());
17
18 // Thread with function is joinable
19 bool executed = false;
20 fl::thread t2([&executed]() {
21 executed = true;
22 });
23 FL_REQUIRE(t2.joinable());
24 t2.join();
25 FL_REQUIRE(executed);
26 FL_REQUIRE(!t2.joinable()); // After join, not joinable
27}
28
29FL_TEST_CASE("fl::thread - this_thread::get_id") {
30 auto main_id = fl::this_thread::get_id();
31
32 fl::thread::id thread_id;
33 fl::thread t([&thread_id]() {
34 thread_id = fl::this_thread::get_id();
35 });
36 t.join();
37
38 // Thread ID should be different from main thread
39 // Compare as bool to avoid stringification issues with GCC 14's thread::id operator<<
40 bool ids_are_different = (thread_id != main_id);
41 FL_REQUIRE(ids_are_different);
42}
43
44FL_TEST_CASE("fl::thread - thread with arguments") {
45 int result = 0;
46 fl::mutex m;
47
48 auto thread_func = [&](int a, int b) {
49 fl::unique_lock<fl::mutex> lock(m);
50 result = a + b;
51 };
52
53 fl::thread t(thread_func, 10, 20);
54 t.join();
55
56 FL_REQUIRE(result == 30);
57}
58
59FL_TEST_CASE("fl::thread - move semantics") {
60 fl::atomic<bool> executed(false);
61
62 fl::thread t1([&executed]() {
63 executed.store(true);
64 });
65
66 FL_REQUIRE(t1.joinable());
67
68 // Move construct

Callers

nothing calls this directly

Calls 5

joinableMethod · 0.80
yieldFunction · 0.50
storeMethod · 0.45
loadMethod · 0.45
fetch_addMethod · 0.45

Tested by

no test coverage detected