make the scoping thing clearer
This commit is contained in:
6
main.cpp
6
main.cpp
@@ -41,7 +41,7 @@ struct Sensors {
|
||||
std::mutex mtx; // making sure the struct isnt accessed by multiple threads at once
|
||||
};
|
||||
|
||||
void sighandler(int s) {
|
||||
void sighandler(int s) { // can i remove int s
|
||||
std::println("[Signal] got SIGINT/SIGTERM, exiting...");
|
||||
sem::main.release();
|
||||
sem::display.release();
|
||||
@@ -147,8 +147,8 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
/* 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
|
||||
then the program leaves the scope, but before that, it destroys the std::jthreads in the "threads" vector
|
||||
this causes all threads to gracefully close and join back into main thread, so we can safely destroy pSensors without segfault
|
||||
*/
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user