Is it possible to kill a spinning thread?

前端 未结 9 1488
遥遥无期
遥遥无期 2021-01-20 19:09

I am using ZThreads to illustrate the question but my question applies to PThreads, Boost Threads and other such threading libraries in C++.

class MyClass: p         


        
9条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 19:27

    As people already said, there is no portable way to kill a thread, and in some cases not possible at all. If you have control over the code (i.e. can modify it) one of the simplest ways is to have a boolean variable that the thread checks in regular intervals, and if set then terminate the thread as soon as possible.

提交回复
热议问题