26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Using message passing<br />

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG.<br />

More about channels<br />

Who sent the message?<br />

In the server example above, we saw that the server created just one channel. It could<br />

certainly have created more, but generally, servers don’t do that. (The most obvious<br />

example of a server <strong>with</strong> two channels is the Transparent Distributed Processing (TDP,<br />

also known as Qnet) native network manager — definitely an “odd” piece of<br />

software!)<br />

As it turns out, there really isn’t much need to create multiple channels in the real<br />

world. The main purpose of a channel is to give the server a well-defined place to<br />

“listen” for messages, and to give the clients a well-defined place to send their<br />

messages (via a connection). About the only time that you’d have multiple channels in<br />

a server is if the server wanted to provide either different services, or different classes<br />

of services, depending on which channel the message arrived on. The second channel<br />

could be used, for example, as a place to drop wake up pulses — this ensures that<br />

they’re treated as a different “class” of service than messages arriving on the first<br />

channel.<br />

In a previous paragraph I had said that you could have a pool of threads running in a<br />

server, ready to accept messages from clients, and that it didn’t really matter which<br />

thread got the request. This is another aspect of the channel abstraction. Under<br />

previous versions of the <strong>QNX</strong> family of operating systems (notably <strong>QNX</strong> 4), a client<br />

would target messages at a server identified by a node ID and process ID. Since <strong>QNX</strong><br />

4 is single-threaded, this means that there cannot be confusion about “to whom” the<br />

message is being sent. However, once you introduce threads into the picture, the<br />

design decision had to be made as to how you would address the threads (really, the<br />

“service providers”). Since threads are ephemeral, it really didn’t make sense to have<br />

the client connect to a particular node ID, process ID, and thread ID. Also, what if that<br />

particular thread was busy? We’d have to provide some method to allow a client to<br />

select a “non-busy thread <strong>with</strong>in a defined pool of service-providing threads.”<br />

Well, that’s exactly what a channel is. It’s the “address” of a “pool of<br />

service-providing threads.” The implication here is that a bunch of threads can issue a<br />

MsgReceive() function call on a particular channel, and block, <strong>with</strong> only one thread<br />

getting a message at a time.<br />

Often a server will need to know who sent it a message. There are a number of reasons<br />

for this:<br />

• accounting<br />

• access control<br />

• context association<br />

• class of service<br />

• etc.<br />

98 Chapter 2 • Message Passing April 30, 2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!