author | Dominic Pinkman <dominic.pinkman@nokia.com> |
Tue, 20 Jul 2010 12:00:49 +0100 | |
changeset 13 | 48780e181b38 |
parent 7 | 51a74ef9ed63 |
permissions | -rw-r--r-- |
13
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
1 |
<?xml version="1.0" encoding="utf-8"?> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
2 |
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
3 |
<!-- This component and the accompanying materials are made available under the terms of the License |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
4 |
"Eclipse Public License v1.0" which accompanies this distribution, |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
5 |
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
6 |
<!-- Initial Contributors: |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
7 |
Nokia Corporation - initial contribution. |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
8 |
Contributors: |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
9 |
--> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
10 |
<!DOCTYPE concept |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
11 |
PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
12 |
<concept id="GUID-056B9A65-EC59-4B2E-9F10-E487343B5F5F" xml:lang="en"><title>SemaphoreExample: thread synchronisation using semaphores</title><shortdesc>Explains how to use Semaphores to achieve thread synchronization.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
13 |
<p>It is recommended to use semaphores instead of thread priorities |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
14 |
for the following reasons:<ul> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
15 |
<li><p> In a uniprocessor environment, setting the thread priorities |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
16 |
does not guarantee prioritized or serialized execution.</p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
17 |
<li><p>In a multiprocessor or SMP environment, thread priorities are |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
18 |
irrelevant as multiple threads can run simultaneously.</p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
19 |
</ul></p> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
20 |
<section id="GUID-48668C9B-6B42-4FE8-899B-403D5EB5FB53"><title>Download</title> <p>Click on the following link to download the example: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/zips/guid-34775913-c5c2-41ba-a591-827039bbe7af.zip" scope="external">SemaphoreExample.zip</xref></p><p>Click: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/guid-34775913-c5c2-41ba-a591-827039bbe7af.html" scope="peer">browse</xref> to view the example code. </p></section> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
21 |
<section id="GUID-2E531F3D-EEC8-40FD-9F32-2071FDECAE61"><title>Description: </title><p> The example creates a database containing a table of three columns |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
22 |
with integer entries.</p><p> The example creates two threads:</p><ul> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
23 |
<li><p><codeph>WriterThread</codeph>: This thread calls a periodic |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
24 |
function at an interval of one second, and in each iteration it inserts |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
25 |
one row of integers in the table. </p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
26 |
<li><p><codeph>ReaderThread</codeph>: This thread also calls a periodic |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
27 |
function at an interval of one second, and in each iteration it reads |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
28 |
one row of integers following the last row read.</p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
29 |
</ul><p> The example uses a macro <codeph>USE_SEMAPHORE</codeph> to |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
30 |
show the difference between the code using semaphores and the code |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
31 |
which doesn't use semaphores. When not using semaphores, it is not |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
32 |
guaranteed that the <codeph>ReaderThread</codeph> will be able to |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
33 |
read the database because in an SMP environment, data may not yet |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
34 |
have been written by the <codeph>WriterThread</codeph>.</p><p>Using |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
35 |
a semaphore serializes the thread execution. The read operation waits |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
36 |
on the semaphore until it gets a signal from the write operation. |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
37 |
This ensures that the <codeph>ReaderThread</codeph> only reads a row |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
38 |
from the database after the <codeph>WriterThread</codeph> has written |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
39 |
it. </p></section> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
40 |
<section id="GUID-07CAD3CA-86DB-4245-8565-C618E59718A5"><title>Class |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
41 |
summary</title><ul> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
42 |
<li><p><xref href="GUID-B0E661BC-4058-3256-B9C3-5A4FD52F6DE5.dita"><apiname>RThread</apiname></xref> - A handle to a thread.</p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
43 |
<li><p><xref href="GUID-F4A68645-2265-307F-B951-8295827E000B.dita"><apiname>RDbStoreDatabase</apiname></xref> - DBMS Store database implementation</p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
44 |
<li><p><xref href="GUID-AED27A76-3645-3A04-B80D-10473D9C5A27.dita"><apiname>RSemaphore</apiname></xref> - Used for thread synchronization. </p></li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
45 |
</ul></section> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
46 |
<section id="GUID-863B0EDF-F3F8-4345-9FEE-824350A2DBCE"><title>Building |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
47 |
and configuring</title> <p>To build the example: </p> <ul> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
48 |
<li id="GUID-037442C7-2436-5152-9A3E-9DC0B4283A9C"><p>The example |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
49 |
builds an executable called <filepath>semaphoreexample.exe</filepath> in the standard location. </p> </li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
50 |
<li id="GUID-B7C849B9-0885-5253-A78B-71854F86D772"><p>You can build |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
51 |
the example from your IDE or the command line. </p> <p>If you use |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
52 |
an IDE, import the <filepath>bld.inf</filepath> file of the example |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
53 |
into your IDE, and use the build command of the IDE. </p> <p>If you |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
54 |
use the command line, open a command prompt, and set the current directory |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
55 |
to the source code directory of the example. You can then build the |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
56 |
example with the SBSv1 build tools with the following commands: </p> <p><userinput>bldmake bldfiles</userinput> </p> <p><userinput>abld |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
57 |
build</userinput> .</p> </li> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
58 |
</ul> </section> |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
59 |
<section id="GUID-278DD8CF-28AF-4826-B938-20EC19F3A5B0"><title>Running |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
60 |
the example</title> <p>The example code contains a macro<codeph>USE_SEMAPHORE</codeph> in the <filepath>mmp</filepath> file. By default it is commented |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
61 |
out and on execution the example runs without using semaphores; the |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
62 |
macro should be uncommented to use semaphores. The console output |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
63 |
will generally look the same whether using semaphores or not if there |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
64 |
is a single processor, but differences will occur in an SMP environment. |
48780e181b38
Week 28 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 1897 and Bug 1522.
Dominic Pinkman <dominic.pinkman@nokia.com>
parents:
7
diff
changeset
|
65 |
Run the example following the instructions provided in the console. </p> </section> |
7
51a74ef9ed63
Week 12 contribution of API Specs and fix SDK submission
Dominic Pinkman <Dominic.Pinkman@Nokia.com>
parents:
diff
changeset
|
66 |
</conbody></concept> |