Symbian3/PDK/Source/GUID-C7B748CF-D080-5448-98AF-1634D821E713.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 16 Jul 2010 17:23:46 +0100
changeset 12 80ef3a206772
parent 9 59758314f811
permissions -rw-r--r--
Week 28 contribution of PDK documentation content. See release notes for details. Fixes bugs Bug 1897, Bug 344, Bug 2681, Bug 463, Bug 1522.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-C7B748CF-D080-5448-98AF-1634D821E713" xml:lang="en"><title> SMP Example</title><shortdesc>This example demonstrates symmetric multiprocessing using
multiple threads. </shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>This example shows the differences between code running in a unicore
environment and in a multiprocessor environment.</p>
<section id="GUID-7AC2BE12-4F01-4140-8379-672475DE7681"><title>Download</title> <p>Click on the following link to download the example: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/zips/guid-577596d8-76a2-4a41-aa0f-deefe5638e23.zip" scope="external">SmpExample.zip</xref></p><p>Click: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/guid-577596d8-76a2-4a41-aa0f-deefe5638e23.html" scope="peer">browse</xref> to view the example code. </p> </section>
<section id="GUID-7A70847E-40A2-4267-9BD4-36F88F48C84A"><title>Class
summary</title><ul>
<li><p><xref href="GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5.dita"><apiname>RThread</apiname></xref> - A handle to a thread.</p></li>
<li><p><xref href="GUID-F4A68645-2265-307F-B951-8295827E000B.dita"><apiname>RDbStoreDatabase</apiname></xref> - DBMS Store database implementation</p></li>
</ul></section>
<section id="GUID-BE13F08D-09FD-41DF-9210-D46EBECADA69"><title>Design
and implementation</title> <p>The example creates two databases named
DBforSMP1.db and DBforSMP2.db and three threads: </p> <ul>
<li id="GUID-F4EE1C84-FE30-5C99-872B-1881D852CAEA"><p> <codeph>WriterThread1</codeph>: It creates the DBforSMP1.db database and writes integers to it.
The thread has the lowest priority amongst all the threads. </p> </li>
<li id="GUID-7B2D0419-E069-59FA-A6CE-70EBC203F656"><p> <codeph>WriterThread2</codeph>: It creates the DBforSMP2.db database and writes some integers to
it. The thread has highest priority amongst all the threads. </p> </li>
<li id="GUID-7C9584F2-E6C8-5A02-B4C2-4845CF4BAA36"><p> <codeph>ReaderThread</codeph>: It reads the two databases and prints the output to the console.
It has normal priority. </p> </li>
</ul> <p>In a unicore enviroment, the threads are executed according
to their priorities. This means first <codeph> WriterThread2</codeph>, then <codeph>ReaderThread</codeph> and finally <codeph>WriterThread1</codeph> is executed. Hence <codeph>ReaderThead</codeph> can only print the
contents of the DBforSMP2.db in the console because DBforSMP1 is empty.
in an SMP environment, threads run simultaneously and <codeph>ReaderThread</codeph> can print the contents of both the databases. </p> </section>
<section id="GUID-3686F166-C4DD-4269-9B9C-F0027F53547E"><title>Building
and configuring</title> <p>To build the example: </p> <ul>
<li id="GUID-037442C7-2436-5152-9A3E-9DC0B4283A9C-GENID-1-12-1-18-1-1-9-1-4-1-25-1-30-1-3-5-3-1"><p>The example
builds an executable called <filepath>smpexample.exe</filepath> in
the standard location. </p> </li>
<li id="GUID-B7C849B9-0885-5253-A78B-71854F86D772-GENID-1-12-1-18-1-1-9-1-4-1-25-1-30-1-3-5-3-2"><p>You can build
the example from your IDE or the command line. </p> <p>If you use
an IDE, import the <filepath>bld.inf</filepath> file of the example
into your IDE, and use the build command of the IDE. </p> <p>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: </p> <p><userinput>bldmake bldfiles</userinput> </p> <p><userinput>abld
build</userinput> </p> </li>
</ul> </section>
<section id="GUID-F773B722-7612-4BAF-99CB-84E39CE10C40"><title>Running
the example</title> <p>To test the example in an SMP environment,
add <codeph>crazyscheduling on</codeph>in the <filepath>epoc32\data\epoc.ini</filepath> 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. </p> </section>
</conbody></concept>