vendredi 10 juillet 2020

Boolean stop signal between threads

What is the simplest way to signal a background thread to stop executing?

I have used something like:

volatile bool Global_Stop = false;

void do_stuff() {
    while (!Global_Stop) {
        //...
    }
}

Is there anything wrong with this? I know for complex cases you might need "atomic" or mutexes, but for just boolean signaling this should work, right?

Aucun commentaire:

Enregistrer un commentaire