Kill Thread in Pthread Library

前端 未结 5 514
谎友^
谎友^ 2020-11-27 05:14

I use pthread_create(&thread1, &attrs, //... , //...); and need if some condition occured need to kill this thread how to kill this ?

5条回答
  •  悲&欢浪女
    2020-11-27 05:22

    I agree with Antti, better practice would be to implement some checkpoint(s) where the thread checks if it should terminate. These checkpoints can be implemented in a number of ways e.g.: a shared variable with lock or an event that the thread checks if it is set (the thread can opt to wait zero time).

提交回复
热议问题