03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

The process of switching execution between one thread and another is context switching.<br />

Like any other system, Symbian OS's scheduler is written carefully to minimize the<br />

overheads involved in context switching.<br />

Nevertheless, context switching is much more expensive than, say, a function call. The most<br />

expensive type of context switch is between a thread in one process and a thread in another<br />

because a process switch also involves many changes to the MMU settings, and various<br />

hardware caches must be flushed. It's much cheaper to context switch between two threads<br />

in the same process.<br />

Typically, each Symbian OS application uses its own process that consists of just one main<br />

thread. Each server also uses its own process and just one thread. The decision to use a<br />

separate process for each application and server is one of security – a process cannot<br />

deliberately or accidentally change another process' memory. In cases where servers are<br />

designed to cooperate closely together, they are sometimes packaged into a single process<br />

so that context switching between them is cheaper. Thus, all the major communicationsrelated<br />

servers in Symbian OS – serial, sockets, and telephony – run in the same process.<br />

How can an application or server run effectively in a single thread? Don't sophisticated<br />

applications need to perform background tasks? And shouldn't a server have a single thread<br />

for each client? Symbian OS implements sophisticated applications and servers using only a<br />

single thread because it has a good event-handling system based on active objects. I'll<br />

return to that in the Event Handling section below.<br />

2.4 Executable Programs<br />

As far as the CPU is concerned, a C++ program is just a series of instructions. But if we<br />

want to manage software development and deployment effectively, we have to group code in<br />

more convenient packages. The packages Symbian OS uses are closely based on those<br />

used by Windows NT and similar systems. They are as follows:<br />

� a .exe – a program with a single main entry point E32Main(). When the system<br />

launches a new .exe, it first creates a new process. The entry point is then called in the<br />

context of the main thread of that process.<br />

� A dynamic link library or DLL – a library of program code with potentially many entry<br />

points. The system loads a DLL into the context of an existing thread (and therefore an<br />

existing process).<br />

Both these are executables. I'll use 'executable' when I mean either a .exe or a DLL. I'll<br />

never use just 'executable' if I mean a .exe specifically – I'll use '.exe'.<br />

There are two important types of DLL, which are as follows:<br />

� A shared library DLL provides a fixed API that can be used by one or more programs.<br />

Most shared library DLLs have the extension .dll. Executables are marked with the<br />

shared libraries they require and, when the system loads the executable at runtime, the<br />

required shared libraries are loaded automatically. This happens recursively, so any<br />

shared libraries needed by the shared libraries are also loaded, until everything required<br />

by the executable is ready.<br />

� A polymorphic DLL implements an abstract API such as a printer driver, sockets<br />

protocol, or an application. Such DLLs typically use an extension other than .dll – .prn,<br />

.prt, or .app, for instance. In Symbian OS, polymorphic DLLs usually have a single entry<br />

point, which allocates and constructs a derived class of some base class associated<br />

with the DLL. Polymorphic DLLs are usually loaded explicitly by the program that<br />

requires them.<br />

2.4.1 The Place of Execution

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

Saved successfully!

Ooh no, something went wrong!