Question about messages in SVR2

P. D. Guthrie pdg at ihdev.UUCP
Fri Nov 1 08:33:24 AEST 1985


In article <862 at whuxlm.UUCP> wws at whuxlm.UUCP (Stoll W William) writes:
>I have a question about how msgrcv calls are handled by the
>system.  If several processes each call msgrcv with differing
>negative mtypes and another process sends a message, who
>gets first crack at the message?  Or can more than one process
>receive the message?
>
>For example, suppose
>
>   |    proc A calls msgrcv() with mtype -3
> time   proc B calls msgrcv() with mtype -5
>   |    proc C calls msgrcv() with mtype -1
>   V    proc D calls msgsnd() with mtype 1
>
>Who receives the message sent by proc D?  Here are my guesses
>in decreasing order of probability (in my eyes anyway):
>
It seems to me that all processes awaiting these messages get woken up,
but only the first one in the run queue to get there can receive it.  I
have a program that will run fine on our Amdahls, but due to a strange
'bug', it will not work on a Vax. The 'bug':
   Process A			Process B
   ----------			----------
1  				msgrcv (any type)
2  msgsnd
3    .				msgsnd
4    .
5    .
6  msgrcv (any type)
Process B is waiting for a signal to start data transmition from 'A',
which 'A' sends.  'B' then starts tranmitting data for 'A'.  'A'  after
sending (line 2) the 'start' signal to 'B',  does some various menial
tasks, (3,4,5) and then sets down to receive (6) the data 'B' is tranmitting
(3).  The problem is that process A in 6 somehow manages to receive the
message that it tranmitted in 2!  A possible explanation is below.
So a question to someone more enlightened : Is this a bug or a feature?

>1) Any of A, B, and C may receive the message, depending on who
>   happens to get the processor first.
I think so
>2) Process A gets the message because it called msgrcv() first.
I don't think so
>3) Process C gets the message because abs(-1) == mtype of the
>   message that was sent.
It shouldn't as all three msgrcv's would still be going for it
>4) All three processes (A, B, and C) get the message.
No.
>
>The reason I suspect guess (1) is that I peeked at msg.c and
>it appears that when a message gets sent, a wakeup gets done
>to all procs sleeping on that msqid_ds structure (or the system
>equivalent -- I don't remember).  Since I would prefer that
>guess (2) is correct (and it makes more sense to me), I hope
>that somebody will tell me that I'm wrong.
Yes, I believe you are correct, and my problem occured becase my process
A did a msgsnd, then didn't lose its quantum slice before it did
a msgrcv on the lightly loaded Vax, but did on the Amdahl.
>
>Can anyone enlighten me here?  My apologies if this subject has
>come up before; if so, please send private mail to
>
>Bill Stoll, ihnp4!whuxlm!wws

Anyone know with more certainty?  I will be really disappointed if at
least Guy Harris doesn't reply :-}

				Paul Guthrie



More information about the Comp.unix.wizards mailing list