Windows Event implementation in Linux using conditional variables?

后端 未结 3 2016
星月不相逢
星月不相逢 2020-12-31 15:22

I am trying to implement very simple Windows events in Linux. Only for my scenario - 3 threads, 1 main and 2 secondary. Each of secondary threads raise 1 event by SetEvent a

3条回答
  •  臣服心动
    2020-12-31 15:31

    There was similar question on stackoverflow already: WaitForSingleObject and WaitForMultipleObjects equivalent in linux

    In addition you can use semaphores:

    sem_t semOne  ;
    sem_t semTwo  ;
    sem_t semMain ;
    

    In main thread:

    sem_init(semOne,0,0) ;
    sem_init(semTwo,0,0) ;
    sem_init(semMain,0,0) ;
    
    ...
    
    
    sem_wait(&semMain);
    
    // Thread 1
    sem_wait(&semOne);
    sem_post(&semMain);
    
    
    // Thread 2
    sem_wait(&semTwo);
    sem_post(&semMain);
    

    Detailed description and various examples could be found here: ------http://www.ibm.com/developerworks/linux/library/l-ipc2lin3/index.html

    The previous link is no longer available. The most recent archived version at The Internet Archive's Wayback Machine is: https://web.archive.org/web/20130515223326/http://www.ibm.com/developerworks/linux/library/l-ipc2lin3/index.html

提交回复
热议问题