Operating System - HP-UX
1849294 Members
6692 Online
104042 Solutions
New Discussion

semop problem on hp-ux 11.23 for itanium(rx2600 server)

 
zhengyongjun
New Member

semop problem on hp-ux 11.23 for itanium(rx2600 server)

I have a program, and it works well on hp-ux-11.00 for pa-risc. And I compile it on hp-ux-11.00 for pa-risc, then copy the execute code to hp-ux-11.23 for itanium, it also works well. But when i compile an run it on hp-ux-11.23 for itanium, it does not work. It seem to be hanging forever at semop() system call.

Any body can figure out the problem. thanks.
source code please attachment.
4 REPLIES 4
Don Morris_1
Honored Contributor

Re: semop problem on hp-ux 11.23 for itanium(rx2600 server)

Boy, this is a little strange.

Your problem is the semctl() call is not setting the semaphore to 1 in the first place. (I tracked this down by using q4 while the process was stalled and looking at the sleep channel for the parent and child (the fact that they were both sleeping [and therefore in a P() op was a big clue, the semaphore value being 0 confirmed it] ).

The reason the PA code works and the IPF code doesn't seems to be due to a change in the header. The 11.0 header states:

/* The fourth argument to semctl() varies depending on the value of
its first argument. If desired, "union semun" can be declared
by the user, but this is not necessary since the individual
member can just be passed as the argument. */

This is what you do... and it worked (presumably the semun structure gets added somewhere in the compilation [haven't tracked this exact sequence down]).

For 11.20 and later (and the fact that it came in with 11.20 makes it rather hard for me to track down exactly why / where this was changed, sorry), the header now states:

/* The fourth argument to semctl() is optional and varies depending
* on the value of its first argument. If required, it is of type
* "union semun" which the application program must explicitly declare:
*
* union semun {
* int val;
* struct semid_ds *buf;
* unsigned short *array;
* } arg;
*/

And it means it. When I changed your source code to the following:

#define array_size 1000 /* number of elements in shared memory*/

typedef union semun {
int val;
struct semid_ds *buf;
ushort *array;
} arg;



arg init_sem_value;

init_sem_value.val = 1;


The code works.

# cc +DD32 -o odd odd.c
# ./odd

process pid=0,partial_sum=250000

process pid=6859,partial_sum=250500

the sum of 1 to 1000 is 500500

# uname -a
HP-UX vmialp14 B.11.23 U ia64 1634551262 unlimited-user license

The semctl() man page shows the union being defined... so I believe this is the intended behavior.
Don Morris_1
Honored Contributor

Re: semop problem on hp-ux 11.23 for itanium(rx2600 server)

I did a little asking around. The header files differ -- but the man page for semctl(2) from 11.0 and later *do* document the need to define this union.

The union addresses difference in PA vs. IPF argument passing down into the kernel (and the Aries emulator is doing the switch for you).
zhengyongjun
New Member

Re: semop problem on hp-ux 11.23 for itanium(rx2600 server)

Don Morris,

Thank you!
zhengyongjun
New Member

Re: semop problem on hp-ux 11.23 for itanium(rx2600 server)

Don Morris,
Thank you very much. You are a great help.
It really work, and one of my message comunicate program also has the same problem, i have worked it out. Thanks again!