小编Rya*_*n K的帖子

pthread_cancel()函数无法终止线程

我正在使用pthread_create()pthread_cancel()函数来创建一个多线程程序,但我注意到它pthread_cancel()并没有真正终止它应该的线程.

void check(void *param){
    header_t *Bag = (header_t *) param;
    pthread_t timer_thread;
    while(true){
        if(Bag->size && TIMER_OFF){
            pthread_create(&timer_thread, NULL, (void *) &timer, (void *) Bag);
            printf("\nCREATE THREAD ID = %d\n", timer_thread);
            // ADD
        }
        else if(!TIMER_OFF && Bag->size >= 2 && Bag->next->time <= CURRENT_APT_TIME && CRRENT_TAG != Bag->next->tag){
            printf("\nOLD THREAD ID = %d TO BE CANCELLED\n", timer_thread);
            pthread_cancel(timer_thread);
            pthread_create(&timer_thread, NULL, (void *) &timer, (void *) Bag);
            printf("\nNEW THREAD ID = %d\n", timer_thread);
            // Replace
        } …
Run Code Online (Sandbox Code Playgroud)

c multithreading pthreads

3
推荐指数
1
解决办法
5920
查看次数

标签 统计

c ×1

multithreading ×1

pthreads ×1