I have the following C code, where variables prefixed by sm are shared by two processes proc1 and proc2. Therefore the sem
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.