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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Multiple threads<br />

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

other pile, and so on, all the while looking at your doorway to see if someone else is<br />

coming around <strong>with</strong> even more work.<br />

The server/subserver model would make a lot more sense here. In this model, we have<br />

a server that creates several other processes (the subservers). These subservers each<br />

send a message to the server, but the server doesn’t reply to them until it gets a request<br />

from a client. Then it passes the client’s request to one of the subservers by replying to<br />

it <strong>with</strong> the job that it should perform. The following diagram illustrates this. Note the<br />

direction of the arrows — they indicate the direction of the sends!<br />

Client 1<br />

Subserver 1<br />

Server<br />

Client 2<br />

Subserver2<br />

Server/subserver model.<br />

If you were doing a job like this, you’d start by hiring some extra employees. These<br />

employees would all come to you (just as the subservers send a message to the server<br />

— hence the note about the arrows in the diagram above), looking for work to do.<br />

Initially, you might not have any, so you wouldn’t reply to their query. When someone<br />

comes into your office <strong>with</strong> a folder full of work, you say to one of your employees,<br />

“Here’s some work for you to do.” That employee then goes off and does the work. As<br />

other jobs come in, you’d delegate them to the other employees.<br />

The trick to this model is that it’s reply-driven — the work starts when you reply to<br />

your subservers. The standard client/server model is send-driven because the work<br />

starts when you send the server a message.<br />

So why would the clients march into your office, and not the offices of the employees<br />

that you hired? Why are you “arbitrating” the work? The answer is fairly simple:<br />

you’re the coordinator responsible for performing a particular task. It’s up to you to<br />

ensure that the work is done. The clients that come to you <strong>with</strong> their work know you,<br />

but they don’t know the names or locations of your (perhaps temporary) employees.<br />

As you probably suspected, you can certainly mix multithreaded servers <strong>with</strong> the<br />

server/subserver model. The main trick is going to be determining which parts of the<br />

“problem” are best suited to being distributed over a network (generally those parts<br />

that won’t use up the network bandwidth too much) and which parts are best suited to<br />

being distributed over the SMP architecture (generally those parts that want to use<br />

common data areas).<br />

So why would we use one over the other? Using the server/subserver approach, we<br />

can distribute the work over multiple machines on a network. This effectively means<br />

88 Chapter 2 • Message Passing April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!