This example demonstrates symmetric multiprocessing using multiple threads.
This example shows the differences between code running in a unicore environment and in a multiprocessor environment.
Click on the following link to download the example: SmpExample.zip
Click: browse to view the example code.
The example creates two databases named DBforSMP1.db and DBforSMP2.db and three threads:
WriterThread1: It creates the DBforSMP1.db database and writes integers to it. The thread has the lowest priority amongst all the threads.
WriterThread2: It creates the DBforSMP2.db database and writes some integers to it. The thread has highest priority amongst all the threads.
ReaderThread: It reads the two databases and prints the output to the console. It has normal priority.
In a unicore enviroment, the threads are executed according to their priorities. This means first WriterThread2, then ReaderThread and finally WriterThread1 is executed. Hence ReaderThead can only print the contents of the DBforSMP2.db in the console because DBforSMP1 is empty. in an SMP environment, threads run simultaneously and ReaderThread can print the contents of both the databases.
To build the example:
The example builds an executable called smpexample.exe in the standard location.
You can build the example from your IDE or the command line.
If you use an IDE, import the bld.inf file of the example into your IDE, and use the build command of the IDE.
If you use the command line, open a command prompt, and set the current directory to the source code directory of the example. You can then build the example with the SBSv1 build tools with the following commands:
bldmake bldfiles
abld build
To test the example in an SMP environment, add crazyscheduling onin the epoc32\data\epoc.ini file. This emulates SMP behaviour in the techview emulator. Execute the example in both unicore and multiprocessor environment and see the difference. Run the example following the instructions provided in the console.
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.