diff --git a/main.cpp b/main.cpp index c59620d..1578e38 100644 --- a/main.cpp +++ b/main.cpp @@ -143,18 +143,18 @@ int main(int argc, char* argv[]) { Sensors* pSensors = new Sensors; std::println("[main] size of sensor struct is {} bytes", sizeof(Sensors)); - std::vector> funcs = {displayThread, hassThread, sensorsThread}; + std::function funcs[] = {displayThread, hassThread, sensorsThread}; // array of functions - /* wtf is this? - this spins up funcs as threads and halts until sMain semaphore is released in sighandler - its scoped because when sMain is released, program waits until all the threads join back before leaving the scope - threads object has to be inside the scope too because destruction of std::jthread is what actually makes threads join. + /* what the fucking kind of code is this + this code below spins up display/sensors/homeassistant functions as threads and halts until sem::main is released in sighandler + its scoped because when sem::main is released, program destroys the std::jthreads and the vector before leaving the scope + this causes all threads to join back into main thread before leaving the scope, so we can safely destroy pSensors without segfault */ { std::vector threads; for (auto& f : funcs) - threads.emplace_back(f, pSensors); + threads.emplace_back(f, pSensors); // params: function, stop_token (implied), pointer to sensor struct sem::main.acquire(); }