Operating System - HP-UX
1753818 Members
8050 Online
108805 Solutions
New Discussion юеВ

semop() hanging forever on HP-UX 11.23 itanium

 
SOLVED
Go to solution
Goutham YJ
Advisor

semop() hanging forever on HP-UX 11.23 itanium

Hi All,

The semop() call is hanging forever in my code. Please find the code below.

Can anyone make out what's wrong? The same code works well on PA-RISC systems with HP-UX 11.11.


if (!getWriteLock())
{
OSCMon().outputAlarm(SIAALRMRTGTBLERR,
ALARMCRITICAL,
"Error in NpaNxxRTWriter::update: semaphore failure.");
throw exception("Error in NpaNxxRTWriter::update -> semaphore failure.");
}

---------------------------------------------


bool NpaNxxRT::getWriteLock()
{
OSCMon().debugMsg("",
OSCMONTRACEMSGLOWPRIORITY,
"NpaNxxRT: getWriteLock: lock semaphore\n");

struct sembuf sop;

sop.sem_num = 0; // the write lock is the first one
sop.sem_op = -1; // locked
sop.sem_flg = SEM_UNDO; // in case I die

cout << "Before semop" << endl;
int temp = semop(_semid, &sop, 1);
cout << "After semop=" << temp << endl;

return semop(_semid, &sop, 1) == 0;
}



8 REPLIES 8
Dennis Handly
Acclaimed Contributor

Re: semop() hanging forever on HP-UX 11.23 itanium

Did you really want to call semop(2) twice in getWriteLock?

Perhaps you want: return temp >= 0;
Goutham YJ
Advisor

Re: semop() hanging forever on HP-UX 11.23 itanium

Hi Dennis,

I added first semop() for debugging purposes... Plz ignore.. The actual code is

bool NpaNxxRT::getWriteLock()
{
OSCMon().debugMsg("",
OSCMONTRACEMSGLOWPRIORITY,
"NpaNxxRT: getWriteLock: lock semaphore\n");

struct sembuf sop;

sop.sem_num = 0; // the write lock is the first one
sop.sem_op = -1; // locked
sop.sem_flg = SEM_UNDO; // in case I die


return semop(_semid, &sop, 1) == 0;
}
Dennis Handly
Acclaimed Contributor
Solution

Re: semop() hanging forever on HP-UX 11.23 itanium

>return semop(_semid, &sop, 1) == 0;

semop(2) says the correct check is ">=".
Also, how are you calling semctl(2)? There is a common programming mistake you can make on Integrity.
Goutham YJ
Advisor

Re: semop() hanging forever on HP-UX 11.23 itanium

The semctl() is as below:

if (semid > 0)
{
semctl(semid, 0, SETVAL, 1); // start out unlocked
semctl(semid, 1, SETVAL, 0); // shared mem not set
return semid;
}

We are not using the semun union.. Is that causing the issue?
Goutham YJ
Advisor

Re: semop() hanging forever on HP-UX 11.23 itanium

Also semop() call is hanging and not returning anything. So ">=" check is not getting performed.
Dennis Handly
Acclaimed Contributor

Re: semop() hanging forever on HP-UX 11.23 itanium

>We are not using the semun union. Is that causing the issue?

Exactly, you must use that union. The IPF calling conventions require strict adherence to what's documented.
Goutham YJ
Advisor

Re: semop() hanging forever on HP-UX 11.23 itanium

Thanks a lot dennis. You are great help. The problem is resolved after using the semun union for semctl() system calls.

Thanks,
Goutham
Goutham YJ
Advisor

Re: semop() hanging forever on HP-UX 11.23 itanium

Problem resolved as explained above.