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 />

Master<br />

Worker 1<br />

Worker 2 Worker 3 Worker 4 Worker 5<br />

One master, multiple workers.<br />

Multi-threaded server<br />

Using message passing<br />

The solution to this problem is to have the worker programs start up, and ask the<br />

master program if there’s any work to do by sending it a message. Once again, we’ve<br />

used the direction of the arrows in the diagram to indicate the direction of the send.<br />

Now the worker programs are waiting for the master to reply. When something tells<br />

the master program to do some work, it replies to one or more of the workers, which<br />

causes them to go off and do the work. This lets the workers go about their business;<br />

the master program can still respond to new requests (it’s not blocked waiting for a<br />

reply from one of the workers).<br />

Multi-threaded servers are indistinguishable from single-threaded servers from the<br />

client’s point of view. In fact, the designer of a server can just “turn on”<br />

multi-threading by starting another thread.<br />

In any event, the server can still make use of multiple CPUs in an SMP configuration,<br />

even if it is servicing only one “client.” What does that mean? Let’s revisit the fractal<br />

graphics example. When a subserver gets a request from the server to “compute,”<br />

there’s absolutely nothing stopping the subserver from starting up multiple threads on<br />

multiple CPUs to service the one request. In fact, to make the application scale better<br />

across networks that have some SMP boxes and some single-CPU boxes, the server<br />

and subserver can initially exchange a message whereby the subserver tells the server<br />

how many CPUs it has — this lets it know how many requests it can service<br />

simultaneously. The server would then queue up more requests for SMP boxes,<br />

allowing the SMP boxes to do more work than single-CPU boxes.<br />

Now that we’ve seen the basic concepts involved in message passing, and learned that<br />

even common everyday things like the C library use it, let’s take a look at some of the<br />

details.<br />

90 Chapter 2 • Message Passing April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!