[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Pmsg() usage
Ingo Schmidt wrote:
Hi!
OL> I have 2 programs one is something like this:
I use pmsg in exactly that situation and it works fine for me. I guess
you want to synchronize two processes with that, right?
Out of my experience the best way is to always use 0xffff0000+my_pid
as mailbox id for receiving messages and 0xffff0000+receiver_pid as
mailbox id for sending. An example:
There are two processes, A and B with pids 1 and 2.
Now lets do your scenario:
Program A has this code:
pmsg(0,0xffff0001,&r);
printf("A: message received\n");
printf("A: Sending message...");
pmsg(1,0xffff0002,&r);
printf("OK\n");
Pterm();
Program B has this code:
pmsg(2,0xffff0001,&r);
printf("B: message received\n");
Pterm();
Now start program A and then program B and everything will work fine.
Also consider that in pmsg mode 2 the mailbox id for sending and
receiving are usually different (unless you use mailbox IDs like
described above).
I hope this helped.
Yes a lot, now it work! Thanks
Now I have an other problem with Pmsg() and I think it's a bug of Mint.
Here example
Suppose id=1 for a server and 2 clients id=2 and 3
Server is waiting with
Pmsg(0,1,&r);
Then client 2 and 3 decide to send message to server simultaneously, so
before server have to do something
there is 2 message with
Pmsg(2,1,&r2); /* client 2 */
Pmsg(2,1,&r3); /* client 3 */
So server receive message from 2 do what it have to do and send answer:
Pmsg(1,2|0xFFFF0000,&r); /* the answer of client 2 is good the 2 long
value are correct value */
the server so do an other
Pmsg(0,1,&r);
so it receive the message from client 3
do what it have to do, all is ok put value in r then send message to 3 with:
Pmsg(1,3|0xFFFF0000,&r);
So client 3 receive answer UNFORTUNATLY long values in r3 are not modify
so it's wrong, so for me there is a bug.
If I wait answer before accept send a new message with a semaphore all
is Ok.
Olivier