threads and processes

Hi,

I encounter the problems in writing some codes about threads and processes.
I have three processes, Task A is to read the port repeatedly and when
the bit is changed, it sends message to Task B, which is a control task.
After Task B receive the messages, in terms of different received message
it send message to the Task C or Task D . Now when handling the
communications
of these tasks, if I choose the processes to solve this prolem, I can create
one
thread in each process with using MsgSend() and MsgReceive() to communicate.
However,
if I take these task as threads in a single process, does the communication
between
threads in a process use the message passing? Otherwise, what is the
communication way
between the threads in one process?

Could be connectAttach() and ChannelCreate() worked in the two threads of a
process? If
they do, how to set up the connection?


Thanks,

Belinda

Hello,

You can use the message passing between both threads and processes. The only
real difference in setting up the connections are the parameters passed to
ConnectAttach. The hierarchy would still be the same, in the sense that you
would need to have a client/server layout. I’d give you the chapter and
verse on it, but I disremember the reasons. Rob Krten’s “Getting Started
with QNX Neutrino 2” covers message passing.

If you were to use ChannelCreate and ConnectAttach, then for my money, I’d
have Threads C and D create channels and wait for messages from Thread B.
Thread B would connect to both of these channels, and do a MsgSend on
Channel C or D, based on whatever criteria you felt relevant.

Thread B would also create a channel, which Thread A would attach to. When
the data came in, Thread A would MsgSend on Channel B. Once Thread B
completed its MsgReceive, it would MsgReply to unblock Thread A. This would
allow Thread A to continue to poll the hardware.

At this point, one would have the following structure : C and D are servers
to B. B is a server to A. A is a client.

It would probably look something like this in pseudo code:

/*—Thread D /
channel_d = CreateChannel (…);

rcvid = MsgReceive(channel_d, …);
/
do stuff */

MsgReply (rcvid, …);

/*—Thread C */
same as Thread D

/*—Thread B */
coid_c = ConnectAttach (ND_LOCAL_NODE, 0, channel_c, …);
coid_d = ConnectAttach (ND_LOCAL_NODE,0, channel_d,…);

channel_b = ChannelCreate (…);

rcv_from_threadA = MsgReceive (channel_b, …);
/* Immediately Unblock A to allow it to continue to poll */
MsgReply (rcv_from_threadA,…);

/*decide if message pertains to Thread C or D */
if (a)
MsgSend (coid_c, …);
else
MsgSend (coid_d,…);

/*—Thread A */
coid_b = ConnectAttach (ND_LOCAL_NODE, 0, channel_b, …);

/* Poll here */

MsgSend (coid_b, …);

You also may have to consider how fast the data is coming in, and possibly
do a MsgPulse to Thread B. This doesn’t block, but you also are restricted
in how big the data sent is. A pulse consists of an 8 bit code, and a 32 bit
value, which could mean that you are doing many, many pulses.

The final option would be to set up an interrupt to wake up a thread, and do
the required work. This would prevent the polling thread from possibly
hogging the cpu.

Hope this helps.

Cheers,
-Brian

+================================================+
Brian K. Hlady bhlady@qnx.com
OEM Support Rep QSSL
+================================================+

“Belinda” <yye@is2.dal.ca> wrote in message news:9tcuni$rg5$1@inn.qnx.com

Hi,

I encounter the problems in writing some codes about threads and
processes.
I have three processes, Task A is to read the port repeatedly and when
the bit is changed, it sends message to Task B, which is a control task.
After Task B receive the messages, in terms of different received message
it send message to the Task C or Task D . Now when handling the
communications
of these tasks, if I choose the processes to solve this prolem, I can
create
one
thread in each process with using MsgSend() and MsgReceive() to
communicate.
However,
if I take these task as threads in a single process, does the
communication
between
threads in a process use the message passing? Otherwise, what is the
communication way
between the threads in one process?

Could be connectAttach() and ChannelCreate() worked in the two threads of
a
process? If
they do, how to set up the connection?


Thanks,

Belinda

Hello Belinda,


Belinda wrote:

Hi,

I encounter the problems in writing some codes about threads and processes.
I have three processes, Task A is to read the port repeatedly and when
the bit is changed, it sends message to Task B, which is a control task.
After Task B receive the messages, in terms of different received message
it send message to the Task C or Task D . Now when handling the
communications
of these tasks, if I choose the processes to solve this prolem, I can create
one
thread in each process with using MsgSend() and MsgReceive() to communicate.
However,
if I take these task as threads in a single process, does the communication
between
threads in a process use the message passing? Otherwise, what is the
communication way
between the threads in one process?

You can use global variables so all threads can see them.

Could be connectAttach() and ChannelCreate() worked in the two threads of a
process? If
they do, how to set up the connection?


Thanks,

Belinda
\

Regards,
Dave B.