Thread: Eternal block of process with sem_wait ( )

  1. #1
    Registered User
    Join Date
    Jan 2009

    Eternal block of process with sem_wait ( )


    I'm working on a project upon Ubuntu Linux distribution, and I'm intended to use the semaphore interface provided by <semaphore.h>. The actual problem is, that when having two processes, let's say A and B, that lock their critical sections with the same semaphore, let's say s, B tries to lock semaphore (sem_wait) and goes into the CS, A tries to lock semaphore (sem_wait) but is blocked, and then B locks and unlocks (sem_post) the semaphore a lot of times, while A is sitting actionless... Even when B ends, A does not respond, as it seems to be blocked by its sem_wait. I would be grateful if anyone had any idea about this (except bad memory handling and wrong initialization, etc).

    Thanx for any response!

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    If a thread is blocked in sem_wait(), then as soon as the semaphore becomes non-zero (via sem_post() in another thread), that thread should decrement the sem's value and return from sem_wait(). If this isn't the case (assuming the api's have been used correctly) then you may have "priory inversion" which is preventing A from acquiring the semaphore. Meaning that B's priority is higher, which allows it so post and acquire that post in the same quantum - which in turn starves A.


  3. #3
    Registered User
    Join Date
    Jan 2009
    Hm, the really weird thing here is that when B terminates, A still remains blocked, a fact that may rule out priority inversion.. :/

    thnx anyway codeplug!

  4. #4
    Registered User
    Join Date
    Apr 2008
    Are you sure you're working with the same semaphore (did you used an absolute path name if it's a named semaphore?). Could you post only the relevant sections of your code? (semaphore creation and usage), it's hard to tell otherwise.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with forking a process
    By Unitedroad in forum C Programming
    Replies: 10
    Last Post: 10-04-2007, 01:43 AM
  2. process programming
    By St0rM-MaN in forum Linux Programming
    Replies: 2
    Last Post: 09-15-2007, 07:53 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  4. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
Website Security Test