[omniORB] omni_semaphore operation?

Dietmar May dcmay@object-workshops.com
Thu, 10 Aug 2000 20:03:05 -0400


Hi all,

I must be missing something obvious (or maybe NOT so obvious).

The omni_semaphore code for 2.8.0 contains:

void
omni_semaphore::wait(void)
{
    omni_mutex_lock l(m);

    while (value =3D=3D 0)
        c.wait();

    value--;
}

void
omni_semaphore::post(void)
{
    {
        omni_mutex_lock l(m);
        value++;
    }

    c.signal();
}

Now, if wait() is called in thread 1, the mutex 'm' gets locked by =
thread 1. Now when post() is called by thread 2, it also attempts to =
lock 'm'. However, since 'm' is already locked by thread 1, the threads =
would seem to deadlock, since thread 1 will not release 'm' until after =
signal() is called by thread 2 -- but thread 2 is blocked waiting for =
'm', and cannot reach the call to signal().

Or so it seems at first glance.

What am I missing?

Thanks,
Dietmar