同步线程

时间:2018-07-16 09:54:07

标签: c linux pthreads semaphore

如何使两个线程互相等待,直到它们使用pthreads完成一个循环?

void* th1Fn()
{  
    while(1)
    {
        //do something
        printf("I'm done");
        //signal that i'm done
        //wait for thread2 so that I can repeat the cycle
    }
}

void* th2Fn()
{       
    while(1)
    {
        //do something
        printf("I'm done");
        //signal that i'm done
        //wait for thread1 so that I can repeat the cycle
    }
}

1 个答案:

答案 0 :(得分:1)