ubuntu: sem_timedwait not waking (C)

前端 未结 6 1488
花落未央
花落未央 2021-02-06 17:01

I have 3 processes which need to be synchronized. Process one does something then wakes process two and sleeps, which does something then wakes process three and sleeps, which d

6条回答
  •  眼角桃花
    2021-02-06 17:37

    The problem seems to come from passing an invalid timeout argument.

    At least on my machine, the first failure is not ETIMEDOUT but:

    !!!!!! sem2 sem_timedwait failed: Invalid argument, val now 0

    Now, if I write:

      if (ts.tv_nsec >= 1000000)
    

    (note the addition of =) then it works fine. It's another question why the state of semaphore gets (presumably) effed up so that it times out on subsequent attempts or simply blocks forever on straight sem_wait. Looks like a bug in libc or the kernel.

提交回复
热议问题