channels must be created for each of threads ????

Hi,

Anybody, explain me, please.
May be I mistaken…

Look in attachment, please.

If I use the same channel for all of threads (THE_SAME_CHANNEL=1 defined)
then single 1st thread (with tid=2) receives all (or most of) messages sent by
MsgDeliverEvent
from main thread. (attachment AAA)

If I create individual channel for each of threads (THE_SAME_CHANNEL=0 defined)
then it works OK.(attachment BBB)

Q: Why it do not work in 1st case ? As I see thread id is related with rcvid, but why
thread with id=2 received all messages ? (attachment AAA)

Q: Do it mean I must create individual channel for each of my threads ?


Thanks
Vasilii




begin 666 ttt.c
M(VEN8VQU9&4@/’-T9&EO+F@^“B-I;F-L=61E(#QS=&1D968N:#X*(VEN8VQU
M9&4@/’-T9&QI8BYH/@HC:6YC;'5D92 <WES+VEO9G5N8RYH/@HC:6YC;'5D
M92 <WES+V1I<W!A=&-H+F@^“B-I;F-L=61E(#QS:6=N86PN:#X*(VEN8VQU
M9&4@/&5R<FYO+F@^”@HO+R-I;F-L=61E(”)F=6YC<RYH(@H*(V1E9FEN92!3
M24=.3R!324=)3E0*+R\C9&5F:6YE(%-)1TY/(“A324=25$U)3BLQ2 @"@II
M;G0@8VAI9"P@(&-O:60[“FEN=”!C:&ED,2P@8V]I9#$[“G-I9W-E=%]T(’-I
M9W,[“F1I<W!A=&-H7W0@(” @(” @(" @(“ID<’ [”@IS=’)U8W0@;7E?;7-G
M"GL
"7-H;W)T('1Y<&4[”@EI;G0@("!T:60["@ES=’)U8W0@<VEG979E;G0@
M979E;G0[“GT[”@HC9&5F:6YE($U97U!53%-%7T-/1$4@7U!53%-%7T-/1$5?
M34E.059!24PK-0HC9&5F:6YE($U31U]‘259%7U!53%-%(%])3U]-05@K- H*
M(V1E9FEN92!42$5?4T%-15]#2$%.3D5,(#$"G-T871I8R!V;VEDB!P<F]C
M(“AV;VEDB!A<FPH)1DE,12H@9B ](’-T9&]U=#L"6EN=”!M+"!R8RP@
M<VEG.PH)<W1R=6-T(%]M<V=?:6YF;R!M:6YF;SL*“7-I9VEN9F]?=”!S:6YF
M;SL*“7-T<G5C=”!?<‘5L<V4@<‘5L<V4["@ES=’)U8W0@=&EM97-P96,@=&[
M"@ED:7-P871C:%]C;VYT97AT7W0@(" J8W1P.PHO+PEI;G0@8V]I9#L*"@ET
M;RYT=E]S96,@/2!T:6UE*# I(“L@,C [”@ET;RYT=E]N<V5C(#T@,#L*“7L*
M"7-T<G5C=”!M>5]M<V<@;7-G.PH)<W1R=6-T(%]P=6QS92!P=6QS93L*“6EN
M=”!C:&ED,2QC;VED,3L*(VEF("$H5$A%7U-!345?0TA!3DY%3"D*“6-H:60Q
M(#T@0VAA;FYE;$-R96%T92@@,” I.PH)8V]I9#$@/2!#;VYN96-T071T86-H
M("@P+" P+"!C:&ED,2P@7TY43U]3241%7T-(04Y.14PL(# I.PHC96QS90H)
M8VAI9#$]8VAI9#L@8V]I9#$]8V]I9#L*(V5N9&EF"@ES;&5E<"@Q3L"5-)
M1T567U!53%-%7TE.250@“9M<V<N979E;G0L(&-O:60Q+”!324=%5E]054Q3
M15]04DE/7TE.2$52250L($U97U!53%-%7T-/1$4K<'1H<F5A9%]S96QF
"DL
M(# I.PH);7-G+G1Y<&4@/2!-4T=?1TE615]054Q313L*“6US9RYT:60@/2!P
M=&AR96%D7W-E;&8H3L"4US9U-E;F0@&-O:60L("9M<V<L(’-I>F5O9B!M
M<V<L(# L(# I.PHC:68@
%1(15]304U%7T-(04Y.14PI”@ED96QA>2@Q,# I
M.PHC96YD:68*“5-)1T567U!53%-%7TE.250@“9M<V<N979E;G0L(&-O:60Q
M+”!324=%5E]054Q315]04DE/7TE.2$52250L($U97U!53%-%7T-/1$4K<'1H
M<F5A9%]S96QF
"DL(# I.PH);7-G+G1Y<&4@/2!-4T=?1TE615]054Q313L*
M"6US9RYT:60@/2!P=&AR96%D7W-E;&8H3L"4US9U-E;F0@&-O:60L("9M
M<V<L(’-I>F5O9B!M<V<L(# L(# I.PHC:68@
%1(15]304U%7T-(04Y.14PI
M”@ED96QA>2@Q,# I.PHC96YD:68*"7=H:6QE*#$I>PH)"7)C(#T@37-G4F5C
M96EV95!U;’-E("AC:&ED,2P@)G!U;’-E+"!S:7IE;V8@<‘5L<V4L(# I.PH)
M"69P<FEN=&8@&8L(G1I9" E9"!G;W0@<'5L<V4@=VET:"!C;V1E(“5D+”!W
M86ET:6YG(&9O<B E9"!R8W9I9#HE>%QN(BP@"@D)("!P=&AR96%D7W-E;&8H
M
2P@<‘5L<V4N8V]D92P@35E?4%5,4T5?0T]$12MP=&AR96%D7W-E;&8H2P@
M<'5L<V4N=F%L=64N<VEV86Q?:6YT
3L*“7T*“7T*“7)E='5R;B P.PI]”@HC
M9&5F:6YE($XQ(#(P”@IS=&%T:6,@=F]I9”!W86ET7V9OB@IPH)<VAO<G0@
M:6YT(&T@/2 P>#4P,#$["@EI;G0@<F,L(&UM/3 ["@EU;FEO;B!S:6=V86P@
M<W9A;‘5E.PH):6YT(’)C=FED.PH)<W1R=6-T(&UY7VUS9R!M<V<"@EF<’)I
M;G1F(“AS=&1O=70L(”(M+2TM+2TM+2TM+2TM+2TM+2TM+2U<;B(I.PH*“7=H
M:6QE*#$I>PH)(”!S=’)U8W0@;7E?;7-G(&US9W-;3C%=.PH)("!I;G0@<F-V
M:61S6TXQ73L*“2 @:6YT(&D[”@D@(&9O<B H:3TP.R!I/$XQ.VDKRD"0ER
M8W9I9’-;3C%=(#T@+3$["@D@(&9O<B H:3TP.R!I/$XQ.VDKRE["@D)<F-V
M:61S6VE=(#T@37-G4F5C96EV92 H8VAI9"P@)FUS9W-;:5TL(’-I>F5O9B!M
M<V<L(# I.PHC:68@
%1(15]304U%7T-(04Y.14PI"@D)9&5L87DH,3 I.PHC
M96YD:68*“0EI9B H(&US9W-;:5TN=‘EP92 ]/2!-4T=?1TE615]054Q312 I
M>R "0D)37-G4F5P;'D@’)C=FED<UMI72P@,“P@)FTL(’-I>F5O9B!M3L
M"0D)<’)I;G1F*”)S97)V97(Z979E;G0@"5D2!T:60Z)60@<F-V:60Z)7A<
M;B(L<F,L(&US9W-;:5TN=&ED+”!R8W9I9’-;:5TI.PH)"7UE;’-E>PH)“0EP
M<FEN=&8H(G-E<G9E<CH@=6YE>’!E8W1E9”!M97-S86=E(“5D7&XB+”!M<V=S
M6VE=+G1Y<&4I.PH)"7T*“0EM<V=S6VE=+F5V96YT+G-I9V5V7W9A;'5E+G-I
M=F%L7VEN=”
C=FED<UMI73L*“2 @?0H)(”!F;W(@&D],#L@:3Q.,3MI
M
RLI>PHO+PD)("!I9B H<F-V:61S6TXQ72 ^/2 P0H)“0ER8R ]($US9T1E
M;&EV97)%=F5N=” H<F-V:61S6VE=+" F;7-G<UMI72YE=F5N=“D[”@D@('T

M"7T*“7-L965P*#(I.PI]”@IS=&%T:6,@=F]I9"!R=6Y?=&AR96%DR@IPH@
M( EI;G0@:2QR8SL*"7!T:’)E861?871T<E]T(&%T=’(["@EP=&AR96%D7W0@
M=&ED.PH)<'1H<F5A9%]A=‘1R7VEN:70@"9A='1R3L*(" )<‘1H<F5A9%]A
M=‘1R7W-E=&1E=&%C:’-T871E("@F871T<BP@4%1(4D5!1%]#4D5!5$5?1$54
M04-(140I.R "69O<B H:3TP.R!I(#P@,3 [(&DKRE["@D)<F,@/2!P=&AR
M96%D7V-R96%T92 H)G1I9"P@)F%T=’(L(’!R;V,L(# I.PH)?0H)<VQE97 H
M,2D[“GT*“FEN=”!M86EN*&EN=”!A<F=C+"!C:&%R(“HJ87)G=BD*>PH)8VAI
M9” @/2!#:&%N;F5L0W)E871E*" P(“D[”@EC;VED(" ]($-O;FYE8W1!=‘1A
M8V@H(# L(# L(&-H:60L(%].5$]?4TE$15]#2$%.3D5,+" P(“D[“B\O"6-H
M:60Q(#T@0VAA;FYE;$-R96%T92@@,” I.PHO+PEC;VED,2 ]($-O;FYE8W1!
M='1A8V@H(# L(# L(&-H:60Q+”!?3E1/7U-)1$5?0TA!3DY%3"P@," I.PH*
M"7)U;E]T:’)E861S*“D[”@D*"7=A:71?9F]R*“D[”@H)<F5T=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ED
M(#<@9V]T(’!U;’-E(’=I=&@@8V]D92 Q,BP@=V%I=&EN9R!F;W(@,3(@<F-V
M:60Z-C P,#,
=&ED(#@@9V]T(’!U;’-E(’=I=&@@8V]D92 Q,RP@=V%I=&EN
M9R!F;W(@,3,@<F-V:60Z-S P,#,=&ED(#@@9V]T(’!U;’-E(’=I=&@@8V]D
M92 Q,RP@=V%I=&EN9R!F;W(@,3,@<F-V:60Z-S P,#,
=&ED(#D@9V]T(’!U
M;’-E(’=I=&@@8V]D92 Q-“P@=V%I=&EN9R!F;W(@,30@<F-V:60Z.# P,#,*
M=&ED(#D@9V]T(’!U;’-E(’=I=&@@8V]D92 Q-“P@=V%I=&EN9R!F;W(@,30@
M<F-V:60Z.# P,#,=&ED(#$P(&=O="!P=6QS92!W:71H(&-O9&4@,34L(’=A
M:71I;F<@9F]R(#$U(’)C=FED.CDP,# S"G1I9" Q,"!G;W0@<‘5L<V4@=VET
M:"!C;V1E(#$U+"!W86ET:6YG(&9O<B Q-2!R8W9I9#HY,# P,PIT:60@,3$@
M9V]T(’!U;’-E(’=I=&@@8V]D92 Q-BP@=V%I=&EN9R!F;W(@,38@<F-V:60Z
M83 P,#,
=&ED(#$Q(&=O=”!P=6QS92!W:71H(&-O9&4@,38L(’=A:71I;F<@
M9F]R(#$V(’)C=FED.F$P,# S"G1I9” Q,”!G;W0@<‘5L<V4@=VET:"!C;V1E
M(#$U+"!W86ET:6YG(&9O<B Q-2!R8W9I9#HY,# P,PIT:60@,3$@9V]T(’!U
M;’-E(’=I=&@@8V]D92 Q-BP@=V%I=&EN9R!F;W(@,38@<F-V:60Z83 P,#,*
M=&ED(#$Q(&=O="!P=6QS92!W:71H(&-O9&4@,38L(’=A:71I;F<@9F]R(#$V
-(’)C=FED.F$P,# S"@``
`
end

begin 666 Aaa.dat
M:&5R92!42$5?4T%-15]#2$%.3D5,/3$"BTM+2TM+2TM+2TM+2TM+2TM+2TM
M+0IS97)V97(Z979E;G0@
#$S-#4Q,3,X,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2!T:60Z,3 @
M<F-V:60Z.3 P,#,
<V5R=F5R.F5V96YT("@Q,S0U,3$S.# I(‘1I9#HQ,2!R
M8W9I9#IA,# P,PIT:60@,B!G;W0@<‘5L<V4@=VET:"!C;V1E(#<L(’=A:71I
M;F<@9F]R(#<@<F-V:60Z,3 P,#,=&ED(#(@9V]T(’!U;’-E(’=I=&@@8V]D
M92 W+"!W86ET:6YG(&9O<B W(’)C=FED.C$P,# S"G1I9" R(&=O="!P=6QS
M92!W:71H(&-O9&4@.“P@=V%I=&EN9R!F;W(@-R!R8W9I9#HR,# P,PIT:60@
M,B!G;W0@<'5L<V4@=VET:”!C;V1E(#$P+"!W86ET:6YG(&9O<B W(’)C=FED
M.C0P,# S"G1I9" R(&=O="!P=6QS92!W:71H(&-O9&4@,3$L(’=A:71I;F<@
M9F]R(#<@<F-V:60Z-3 P,#,
=&ED(#(@9V]T(’!U;’-E(’=I=&@@8V]D92 Q
M,BP@=V%I=&EN9R!F;W(@-R!R8W9I9#HV,# P,PIT:60@,B!G;W0@<‘5L<V4@
M=VET:"!C;V1E(#$S+"!W86ET:6YG(&9O<B W(’)C=FED.C<P,# S"G1I9" R
M(&=O="!P=6QS92!W:71H(&-O9&4@,30L(’=A:71I;F<@9F]R(#<@<F-V:60Z
M.# P,#,=&ED(#(@9V]T(’!U;’-E(’=I=&@@8V]D92 Q-2P@=V%I=&EN9R!F
M;W(@-R!R8W9I9#HY,# P,PIT:60@,B!G;W0@<‘5L<V4@=VET:"!C;V1E(#$V
M+"!W86ET:6YG(&9O<B W(’)C=FED.F$P,# S"G1I9" R(&=O="!P=6QS92!W
M:71H(&-O9&4@-RP@=V%I=&EN9R!F;W(@-R!R8W9I9#HQ,# P,PIT:60@,B!G
M;W0@<‘5L<V4@=VET:"!C;V1E(#@L(’=A:71I;F<@9F]R(#<@<F-V:60Z,C P
M,#,
=&ED(#(@9V]T(’!U;’-E(’=I=&@@8V]D92 Y+"!W86ET:6YG(&9O<B W
M(’)C=FED.C,P,# S"G1I9" R(&=O="!P=6QS92!W:71H(&-O9&4@,3 L(’=A
M:71I;F<@9F]R(#<@<F-V:60Z-# P,#,=&ED(#(@9V]T(’!U;’-E(’=I=&@@
M8V]D92 Q,2P@=V%I=&EN9R!F;W(@-R!R8W9I9#HU,# P,PIT:60@,B!G;W0@
M<‘5L<V4@=VET:"!C;V1E(#$R+"!W86ET:6YG(&9O<B W(’)C=FED.C8P,# S
M"G1I9" R(&=O="!P=6QS92!W:71H(&-O9&4@,3,L(’=A:71I;F<@9F]R(#<@
M<F-V:60Z-S P,#,
=&ED(#(@9V]T(’!U;’-E(’=I=&@@8V]D92 Q-“P@=V%I
M=&EN9R!F;W(@-R!R8W9I9#HX,# P,PIT:60@,B!G;W0@<'5L<V4@=VET:”!C
M;V1E(#$U+"!W86ET:6YG(&9O<B W(’)C=FED.CDP,# S"G1I9" R(&=O="!P
M=6QS92!W:71H(&-O9&4@,38L(’=A:71I;F<@9F]R(#<@<F-V:60Z83 P,#,*
`
end

vasa <vv40in@mail.ru> wrote:

Look in attachment, please.

Can you post the code (not as an attachment) please?

Q: Why it do not work in 1st case ? As I see thread id is related with rcvid, but why
thread with id=2 received all messages ? (attachment AAA)

See above.

Q: Do it mean I must create individual channel for each of my threads ?

No the channel is bounded to the process, not to the individual thread.

-Adam
amallory@qnx.com

Q: Do it mean I must create individual channel for each of my threads ?
No the channel is bounded to the process, not to the individual thread.
And what about rcvid which is returned from MsgReceive*() call ? What is its meaning ?

I see it have no meaning – it is ignored. All messages are sent to CHANNEL but not to
some PARTICULAR client who was attached to that channel. I thought that message
MsgSend(rcvid,…) is sent to the same one how unblocked previouse rcvid=MsgRecv():


main thread:

chid=ChannelCreate(0);
coid = ConnectAttach(0, 0, chid, NTO_SIDE_CHANNEL, 0);
run_client_threads()
for (i=0;i<10;i++){
rcvid
=MsgReceive(chid); // different 10 threads unblocked this 10 calls of
MsgReceive()
MsgReply (rcvid,);
}
for (i=0;i<10;i++)
rc = MsgDeliverEvent (rcvid,);

client threads:

delay(111) ;
MsgSend (coid, );
while(1)
MsgReceive (chid, );


So, in sample above – messages sent by
MsgDeliverEvent (rcvid,) call
will receive by any of threads, it is may be SINGLE thread will receive ALL of messages
sent !!??

Thus – again, I cannot understand what is that rcvid ?

Vasilii_

vasa <vv40in@mail.ru> wrote:

Q: Do it mean I must create individual channel for each of my threads ?
No the channel is bounded to the process, not to the individual thread.
And what about rcvid which is returned from MsgReceive*() call ? What is its meaning ?
I see it have no meaning – it is ignored. All messages are sent to CHANNEL but not to
some PARTICULAR client who was attached to that channel. I thought that message
MsgSend(rcvid,…) is sent to the same one how unblocked previouse rcvid=MsgRecv():

A “rcvid” is an id valued “ONLY” to the a server (who did the MsgReceive).
It represents a “client” who is currently talking to the server.
It garunteed the server that if server “MsgReply()” on the rcvid, it will
reply to whoever did the MsgSend().

So, in your sample below, (I suppose run_client_threads() actually use
pthread_crete() to create 10 threads), you will got 10 different rcvid,
and no matter what order you MsgReply(), if you “MsgReply(rcvid[5], …)”,
you always reply to the fifth thread who did the MsgSend().

It is strictly saying you “CAN NOT MsgReply()” to same rcvid twice without
MsgReceive() it first. After a “MsgReply(rcvid, …)”, the rcvid is no
longer valued to the server any more.

ONLY EXCEPTION is MsgDelieverEvent(). MsgDelieverEvent() is a “backword”
message passing, it start from “server”, target to “client”. It is used
if the client do not wish to blocking on server, or 2 process must exchange
message between them.

The use of MsgDelieverEvent() usually like this:

  1. he then build up a “event”. (in case the “event” is a pulse, the client
    have to first create a channel, and ConnectAttach() to it to get the
    coid store in “event”).

  2. he did a MsgSend() to the server, saying “if ,
    send back to me”

  3. the server then “remember” both the “event and rcvid”, and MsgReply(rcvid)
    to unblock client.

  4. if the sever find the condition client request is true, it will then
    MsgDelieverEvent(rcvid, theEvent) to notify the client.

The MsgDelieverEvent() take a rcvid, because in case the “event” is a thread
related one (SIGEV_SIGNAL_THREAD, etc), the event will delievered to the client
thread who did the MsgSend() in step 2. In case of a SIGEV_PULSE event,
the event deliever to the connection, pointed by the sigev_coid member. (in
this case, the rcvid is only used to confirm that the clinet have a connection
with server)

Back to your sample, since all your client are MsgReceive() on same channel,
they will receive the event without any order, disregard the order the server
delievered.

If you really want 10 event deliever to 10 different client, then, yes, you
have to create 10 channel, and 10 connection, and build 10 different event
to pass it to server.

However, the usual case is you have 10 different sigev_value.sival_int build
into 10 different “event”, and have all “client” listen on the same channel,
whoever receive the event, they check the sigev_value.sival_int, and do the
associate work.

Hope this could clear the mud :slight_smile:

-xtang

main thread:

chid=ChannelCreate(0);
coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0);
run_client_threads()
for (i=0;i<10;i++){
rcvid> =MsgReceive(chid); // different 10 threads unblocked this 10 calls of
MsgReceive()
MsgReply (rcvid> ,);
}
for (i=0;i<10;i++)
rc = MsgDeliverEvent (rcvid> ,);

client threads:

delay(111) ;
MsgSend (coid, );
while(1)
MsgReceive (chid, );




So, in sample above – messages sent by
MsgDeliverEvent (rcvid> ,) call
will receive by any of threads, it is may be SINGLE thread will receive ALL of messages
sent !!??

Thus – again, I cannot understand what is that rcvid ?

Vasilii


Best regards,
Vasili

Xiaodan Tang <xtang@qnx.com> ÓÏÏÂÝÉÌ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:9mhhjs$imu$1@nntp.qnx.com

vasa <> vv40in@mail.ru> > wrote:
Q: Do it mean I must create individual channel for each of my threads ?
No the channel is bounded to the process, not to the individual thread.
And what about rcvid which is returned from MsgReceive*() call ? What is its meaning ?
I see it have no meaning – it is ignored. All messages are sent to CHANNEL but not to
some PARTICULAR client who was attached to that channel. I thought that message
MsgSend(rcvid,…) is sent to the same one how unblocked previouse rcvid=MsgRecv():

A “rcvid” is an id valued “ONLY” to the a server (who did the MsgReceive).
It represents a “client” who is currently talking to the server.
It garunteed the server that if server “MsgReply()” on the rcvid, it will
reply to whoever did the MsgSend().

So, in your sample below, (I suppose run_client_threads() actually use
pthread_crete() to create 10 threads), you will got 10 different rcvid,
and no matter what order you MsgReply(), if you “MsgReply(rcvid[5], …)”,
you always reply to the fifth thread who did the MsgSend().

It is strictly saying you “CAN NOT MsgReply()” to same rcvid twice without
MsgReceive() it first. After a “MsgReply(rcvid, …)”, the rcvid is no
longer valued to the server any more.

ONLY EXCEPTION is MsgDelieverEvent(). MsgDelieverEvent() is a “backword”
message passing, it start from “server”, target to “client”. It is used
if the client do not wish to blocking on server, or 2 process must exchange
message between them.

The use of MsgDelieverEvent() usually like this:

  1. he then build up a “event”. (in case the “event” is a pulse, the client
    have to first create a channel, and ConnectAttach() to it to get the
    coid store in “event”).

  2. he did a MsgSend() to the server, saying “if ,
    send back to me”

  3. the server then “remember” both the “event and rcvid”, and MsgReply(rcvid)
    to unblock client.

  4. if the sever find the condition client request is true, it will then
    MsgDelieverEvent(rcvid, theEvent) to notify the client.

The MsgDelieverEvent() take a rcvid, because in case the “event” is a thread
related one (SIGEV_SIGNAL_THREAD, etc), the event will delievered to the client
thread who did the MsgSend() in step 2. In case of a SIGEV_PULSE event,
the event deliever to the connection, pointed by the sigev_coid member. (in
this case, the rcvid is only used to confirm that the clinet have a connection
with server)

Back to your sample, since all your client are MsgReceive() on same channel,
they will receive the event without any order, disregard the order the server
delievered.

If you really want 10 event deliever to 10 different client, then, yes, you
have to create 10 channel, and 10 connection, and build 10 different event
to pass it to server.

However, the usual case is you have 10 different sigev_value.sival_int build
into 10 different “event”, and have all “client” listen on the same channel,
whoever receive the event, they check the sigev_value.sival_int, and do the
associate work.

Hope this could clear the mud > :slight_smile:

-xtang

main thread:

chid=ChannelCreate(0);
coid = ConnectAttach(0, 0, chid, _NTO_SIDE_CHANNEL, 0);
run_client_threads()
for (i=0;i<10;i++){
rcvid> =MsgReceive(chid); // different 10 threads unblocked this 10 calls of
MsgReceive()
MsgReply (rcvid> ,);
}
for (i=0;i<10;i++)
rc = MsgDeliverEvent (rcvid> ,);

client threads:

delay(111) ;
MsgSend (coid, );
while(1)
MsgReceive (chid, );


So, in sample above – messages sent by
MsgDeliverEvent (rcvid> ,) call
will receive by any of threads, it is may be SINGLE thread will receive ALL of messages
sent !!??

Thus – again, I cannot understand what is that rcvid ?

Vasilii

Thank You,
I have understood what is rcvid.

But I have one more and the same question about coid (from ConnectAttach call).
What is it ?

in the same example my threads uses single global channel but its performs individual
ConnectAttach call to it.
Thus, its has individual coid to the same channel.
But result is the same as in case of usage of rcvid-s from previouse letter.

As shown in results below – one of threads (1st running thread) receives most of pulses
from server thread, but those pulses sent to different coid-s.
As I can guess – it happens because coid bounds to whole process but not to thread (as described in docs) as chid.
And I think creating individual channel for each of threads is wasting of system resources.
Q:What is solution ?
Q: What is coid ? When it has its meaning ?

Vasilii

// --------source---------
// global
int chid, coid;
struct my_msg{
short type;
int tid, rcvid, coid;
struct sigevent event;
};

#define MY_PULSE_CODE _PULSE_CODE_MINAVAIL+5
#define MSG_GIVE_PULSE _IO_MAX+4

static void* proc (void* arg){
int m, rc;
struct _pulse pulse;
struct my_msg msg;
struct _pulse pulse;
int chid1=chid,coid1=coid;
delay(10);
// chid1 = ChannelCreate (0); // *** if uncomment – it will work OK.***
coid1 = ConnectAttach (0, 0, chid1, _NTO_SIDE_CHANNEL, 0);
SIGEV_PULSE_INIT (&msg.event, coid1, SIGEV_PULSE_PRIO_INHERIT,
MY_PULSE_CODE+pthread_self(), 0);
msg.type = MSG_GIVE_PULSE;
msg.tid = pthread_self();
msg.coid = coid1;
// printf(“client tid:%d coid:%x\n”, msg.tid, msg.coid);
MsgSend (coid, &msg, sizeof msg, 0, 0);
MsgSend (coid, &msg, sizeof msg, 0, 0);
while(1){
// rc = MsgReceive (chid1, &pulse, sizeof pulse, 0);
rc = MsgReceivePulse (chid1, &pulse, sizeof pulse, 0);
fprintf (f,“tid %2d got pulse with code %2d, waiting for %2d rcvid:%x\n”,
pthread_self(), pulse.code, MY_PULSE_CODE+pthread_self(), pulse.value.sival_int);
}
return 0;
}

#define N1 20

static void wait_for(){
short int m = 0x5001;
int rc, mm=0;
union sigval svalue;
int rcvid;
struct my_msg msg;
fprintf (stdout, “--------------------- chid:%x coid:%x\n”,chid,coid);

while(1){
struct my_msg msgs[N1];
int rcvids[N1];
int coids[N1];
int i;
for (i=0; i<N1;i++){
rcvids[N1] = -1;
coids[N1] = -1;
}
for (i=0; i<N1;i++){
rcvids _= MsgReceive (chid, &msgs, sizeof msg, 0);
delay(10);
if ( msgs.type == MSG_GIVE_PULSE

MsgReply (rcvids, 0, &m, sizeof m);
coids = msgs.coid;
printf(“server:event tid:%2d rcvid:%x coid:%x\n”
, msgs.tid, rcvids, msgs.coid);
// rc = MsgDeliverEvent (rcvid, &msg.event);
}else{
printf(“server: unexpected message %d\n”, msgs.type);
}
msgs[i].event.sigev_value.sival_int = rcvids[i];
fflush(stdout);
}
for (i=0; i<N1;i++){
// printf(“server: before deliver message[%d] rcvid:%x coid:%x\n”, i, rcvids[i],
coids[i]);
rc = MsgSendPulse (coids[i], sched_get_priority_min(SCHED_FIFO),
msgs[i].event.sigev_code, coids[i]);
// rc = MsgDeliverEvent (rcvids[i], &msgs[i].event);
// printf(“server: after deliver message[%d] %d\n”, i, rc);
}
}
sleep(2);
}

static void run_threads(){
int i,rc;
pthread_attr_t attr;
pthread_t tid;
pthread_attr_init (&attr);
pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
for (i=0; i < 10; i++){
rc = pthread_create (&tid, &attr, proc, 0);
}
delay(100);
}

int main(int argc, char **argv)
{
chid = ChannelCreate( 0 );
coid = ConnectAttach( 0, 0, chid, NTO_SIDE_CHANNEL, 0 );
run_threads();
wait_for();
return 0;
}

------results-----
--------------------- chid:1 coid:40000002
server:event tid: 2 rcvid:10003 coid:40000004
server:event tid: 3 rcvid:20003 coid:40000005
server:event tid: 4 rcvid:30003 coid:40000006
server:event tid: 5 rcvid:40003 coid:40000007
server:event tid: 6 rcvid:50003 coid:40000008
server:event tid: 7 rcvid:60003 coid:40000009
server:event tid: 8 rcvid:70003 coid:4000000a
server:event tid: 9 rcvid:80003 coid:4000000b
server:event tid:10 rcvid:90003 coid:4000000c
server:event tid:11 rcvid:a0003 coid:4000000d
server:event tid: 2 rcvid:10003 coid:40000004
server:event tid: 3 rcvid:20003 coid:40000005
server:event tid: 4 rcvid:30003 coid:40000006
server:event tid: 5 rcvid:40003 coid:40000007
server:event tid: 6 rcvid:50003 coid:40000008
server:event tid: 7 rcvid:60003 coid:40000009
server:event tid: 8 rcvid:70003 coid:4000000a
server:event tid: 9 rcvid:80003 coid:4000000b
server:event tid:10 rcvid:90003 coid:4000000c
server:event tid:11 rcvid:a0003 coid:4000000d
tid 2 got pulse with code 7, waiting for 7 rcvid:40000004
tid 2 got pulse with code 8, waiting for 7 rcvid:40000005
tid 2 got pulse with code 9, waiting for 7 rcvid:40000006
tid 2 got pulse with code 10, waiting for 7 rcvid:40000007
tid 2 got pulse with code 11, waiting for 7 rcvid:40000008
tid 2 got pulse with code 12, waiting for 7 rcvid:40000009
tid 2 got pulse with code 13, waiting for 7 rcvid:4000000a
tid 2 got pulse with code 14, waiting for 7 rcvid:4000000b
tid 2 got pulse with code 15, waiting for 7 rcvid:4000000c
tid 2 got pulse with code 16, waiting for 7 rcvid:4000000d
tid 3 got pulse with code 8, waiting for 8 rcvid:40000005
tid 4 got pulse with code 9, waiting for 9 rcvid:40000006
tid 5 got pulse with code 10, waiting for 10 rcvid:40000007
tid 6 got pulse with code 11, waiting for 11 rcvid:40000008
tid 7 got pulse with code 12, waiting for 12 rcvid:40000009
tid 8 got pulse with code 13, waiting for 13 rcvid:4000000a
tid 9 got pulse with code 14, waiting for 14 rcvid:4000000b
tid 10 got pulse with code 15, waiting for 15 rcvid:4000000c
tid 11 got pulse with code 16, waiting for 16 rcvid:4000000d
server: unexpected message 0