![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Avoid Duplicates in a file | pssandeep | UNIX for Dummies Questions & Answers | 7 | 03-26-2008 06:36 AM |
| AWK: How to avoid System | sandeep_hi | Shell Programming and Scripting | 0 | 06-23-2006 07:01 AM |
| How to avoid historying my command | ting123 | UNIX for Dummies Questions & Answers | 2 | 05-06-2006 05:58 AM |
| Avoid spam in pine? | a25khan | UNIX for Dummies Questions & Answers | 1 | 12-13-2003 10:50 AM |
| how to lock keyboard without using lock command | dianayun | UNIX for Dummies Questions & Answers | 7 | 06-21-2002 07:05 PM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
avoid semphore lock
we developed a set of system V semphore interface for our application, in general, all of them work normal, seldom cause the deadlock. Here are some important sem_wait and sem_post interface, pls point some suggestion to fixed the deadlock problem: Code:
int sem_wait_V(int id, struct sembuf *sem_pv)
{
sem_pv = new struct sembuf [1] ;
if (sem_op(id,-1, sem_pv)<0)
{
delete sem_pv ;
return -1;
}
delete sem_pv ;
return 0;
}
int sem_post_V(int id, int sem_post_value_V, struct sembuf *sem_pv)
{
if ((sem_post_value_V = semctl(id,0,GETVAL,0)) <0)
{
return -1;
}
if( sem_post_value_V > SEM_POST_LIMIT )
{
if( sem_post_value_V == SEM_POST_LIMIT + 1 ) return -1 ;
return -1 ;
}
sem_pv = new struct sembuf [1] ;
if (sem_op(id,1,sem_pv)<0)
{
delete sem_pv ;
return -1;
}
delete sem_pv ;
return 0;
}
int sem_op(int id,int value, struct sembuf sem_pv[1] )
{
int sem_value ,sem_value1;
sem_pv[0].sem_num = 0 ;
sem_pv[0].sem_flg = 0 ;
if ((sem_pv[0].sem_op =value) == 0)
{
printf("sem_op error: operator is zero !!!!!!!(%d)\n",id) ;
return -1;
}
if ((sem_value = semctl(id,0,GETVAL,0)) <0)
{
perror("semctl create GETVAL");
return -1;
}
again:;
if (semop(id,&sem_pv[0],1)<0)
{
sched_yield() ;
if(errno==EINTR)
{
if ((sem_value1 = semctl(id,0,GETVAL,0)) <0)
{
perror("semctl create GETVAL");
return -1;
}
else
{
if (sem_value != sem_value1 )
return -1;
else
goto again;
}
}
return -1;
}
return 1;
}
Last edited by Frank2004; 02-03-2008 at 11:06 PM.. |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|