View topic - deadlock in semaphore

deadlock in semaphore

anything that doesn't fit to other groups.

deadlock in semaphore

Postby raohansikarao » Tue Mar 02, 2010 7:27 am

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
Active Member
 
Posts: 34
Joined: Thu Feb 25, 2010 4:25 am

Postby Tim » Tue Mar 02, 2010 2:58 pm

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
Tim
Senior Member
 
Posts: 1466
Joined: Wed Mar 10, 2004 12:28 am

Postby maschoen » Tue Mar 02, 2010 4:31 pm

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.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Postby raohansikarao » Wed Mar 03, 2010 8:35 am

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
raohansikarao
Active Member
 
Posts: 34
Joined: Thu Feb 25, 2010 4:25 am

Postby maschoen » Wed Mar 03, 2010 5:36 pm

It will take a day or so.
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

Postby raohansikarao » Thu Mar 04, 2010 4:38 am

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)
raohansikarao
Active Member
 
Posts: 34
Joined: Thu Feb 25, 2010 4:25 am

Resource Manager Template Code

Postby maschoen » Thu Mar 04, 2010 6:53 am

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.
Attachments
admin.zip
(6.07 KiB) Downloaded 238 times
maschoen
QNX Master
 
Posts: 2715
Joined: Wed Jun 25, 2003 5:18 pm

RE: Resource Manager Template Code

Postby raohansikarao » Fri Mar 05, 2010 7:15 am

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)
raohansikarao
Active Member
 
Posts: 34
Joined: Thu Feb 25, 2010 4:25 am


Return to General Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron