Interprocess semaphores sometimes not working as expected

走远了吗. 提交于 2019-11-29 14:40:27

Maybe this is a copy/paste error in the question (you are using copy/paste from the real code, right?), but it looks like you have a bug in proc2's handling:

// ....

else // is proc2
{
    sem_wait( sm_l2f );
    if ( sm_condition )
    {
        sm_value_proc1 = calc_value();  // <---  this should be assigning to
                                        //       sm_value_proc2
        printf( ">>> proc2 value = %u!\n", sm_value_proc2 );
    }
    sem_post( sm_f2l );
} 

Then again, maybe it's a copy/paste error in the actual code?

Also - don't forget that sem_wait() can unblock due to a signal.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!