samedi 23 mai 2020

Best way to terminate a thread from inside the thread or any other safe way

Background: So I am writing a network based application. The application has a part where the threads loops indefinitely and performs some action, also there are other threads which come to life when a new request is received (P.S. these are pre spawned threads).

So, now the question is: These threads mostly use static data, I have not yet come across a situation where I need to dynamically allocate some resource. So these threads use static data, and when the user wants to close the program or the program receives a termination signal, I want to terminate the threads in a safe manner.

So what would be the best way to terminate threads internally or any other safe way

I know declaring global vars would be bad, even if they're atomic or stuff.

Thank you.

P.S: I'm fine with POSIX or C++11 thread based solutions anything is helpful.

Aucun commentaire:

Enregistrer un commentaire