0

I am supposed to create a child thread at every 5 mins. But before starting a new thread, I want to terminate previously created child thread, if still running. So far from web search, I can sense that it is possible with C++11 using future and promise. But any example would help me to get more clear idea on this.

Thanks in advance.

user1228352
  • 569
  • 6
  • 21
  • What are the threads doing? Can they check a flag to see if they should terminate? Perhaps you should look into thread pools instead? – Some programmer dude Jun 12 '19 at 07:04
  • Thread is downloading some delta from the server and apply it to the present file. That's it. I just want to make sure that if previous thread is stuck somewhere, I want to kill it before starting a new thread so that it doesn't keep on creating threads and all of them keep stuck. – user1228352 Jun 12 '19 at 07:10
  • 1
    If your threads tend to "get stuck" I suggest you try to find out why, and fix that problem first. Fixing bugs is always better than working around them. Also, if a thread is "stuck" then there's really nothing you can do, as there's really no way to nicely terminate a thread from the outside (if it's even possible). – Some programmer dude Jun 12 '19 at 07:14
  • Do you ask about how to kill the thread? [That question](https://stackoverflow.com/questions/12207684/how-do-i-terminate-a-thread-in-c11) is about the same, have you checked it? Have you checked other questions, which can be googled with "c++11 kill thread"? – Tsyvarev Jun 12 '19 at 09:19

0 Answers0