The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > HP-UX
.
google unix.com



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 06:01 AM
How to avoid historying my command ting123 UNIX for Dummies Questions & Answers 2 05-06-2006 04: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 06:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-03-2008
Frank2004 Frank2004 is offline
Registered User
  
 

Join Date: Jun 2004
Location: Beijing, China
Posts: 53
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..
  #2 (permalink)  
Old 03-10-2009
Frank2004 Frank2004 is offline
Registered User
  
 

Join Date: Jun 2004
Location: Beijing, China
Posts: 53
hope response, thanks.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 08:45 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0