c - 同步线程

标签 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
    }
}

最佳答案

关于c - 同步线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51359095/

相关文章:

linux - 树莓派进入显示器休眠

javascript - 开发环境建议

c - 嵌套线程创建期间的数据竞争

c - Pthread 屏障与循环连接

c - 是否可以在堆栈上分配结构并将其定义隐藏在源文件中?

linux - 硬链接(hard link)可以指向已删除的文件吗?

无法修改 malloc() 分配的地址处的值

C++ std::thread 结合 C pthread_mutex_t

使用 FramesToSkip CaptureStackBackTrace 不一致

C 将文件逐行读取到字符串数组中并排序