deadlock in semaphore

hi friends … i am having two processes which are accessing same hardware resource, but the condition i require is the resource must be accessed by one process at a time. for that purpose i am using semaphores, here the problem what i am facing is if any process got killed without doing sem post then those two processes are remain in sem wait state only … can any one please suggest me how to avoid this situation

Raohansikarao,

The easiest solution is to add a signal handler to your application and do the sem_post() in the signal handler. Make sure to register to catch all the signals that can indicate a process is terminating abnormally.

Then when your process gets killed it will do the sem_post.

The other more complex option is to use the High Availablity functions built into QNX (search for HA in the documentation).

Tim

This is really basic to QNX.

Write a resource manager. It’s really easy. I built a template a few years ago which just requires filling in some blank areas. I’ll make it available if anyone asks.

The circumstances where this would be unacceptable overhead are rare. In those cases you might want to put a mutex in some shared memory.

can u please post your template … as a newbie to qnx it is very helpful to me to know how to write a resource manager, thanks in advance

It will take a day or so.

my actual requirement is, i have two processes with two different timers one process is running for every 50 ms and another process is running for 10 ms , both processes are accessing same resource which is to be avoid by using semaphore … but the problem i am getting is given above post … so i have to synchronize these two processes with out deadlock condition (here 10ms process is very important so that it has not to wait so much long time like 300 ms and above)

I’m uploading the code here which you are free to use. You will put the code that accesses the resource in user.c. You also will want to modify the admin.h parameters to only allow one thread.

my actual requirement is, i have two processes with two different timers one process is running for every 50 ms and another process is running for 10 ms , both processes are accessing same resource which is to be avoid by using semaphore … but the problem i am getting is given above post … so i have to synchronize these two processes with out deadlock condition (here 10ms process is very important so that it has not to wait so much long time like 300 ms and above)