Linux Threads suspend/resume

后端 未结 9 719
情歌与酒
情歌与酒 2020-12-13 11:10

I\'m writing a code in which I have two threads running in parallel.

1st is the main thread which started the 2nd thread. 2nd thread is just a simple thread executin

9条回答
  •  暖寄归人
    2020-12-13 12:04

    You can use mutex to do that, pseudo code would be:

    While (true) {
        /* pause resume */
        lock(my_lock); /* if this is locked by thread1, thread2 will wait until thread1 */
                       /* unlocks it */
        unlock(my_lock); /* unlock so that next iteration thread2 could lock */
    
        /* do actual work here */
    }
    

提交回复
热议问题