SMP Example

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.

Download

Click on the following link to download the example: SmpExample.zip

Click: browse to view the example code.

Class summary

Design and implementation

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.

Building and configuring

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

Running the example

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.