|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-092C18D4-A525-5562-9BF6-41435E400290" xml:lang="en"><title>LibpThread |
|
13 Example - Using P.I.P.S OECORE </title><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
14 <p>This example application shows, using a P.I.P.S. (P.I.P.S. Is POSIX on |
|
15 Symbian OS) program, the use of the LibpThread library to demonstrate simple |
|
16 multi-threading and synchronisation. </p> |
|
17 <p>The purpose is to create a basic multithreading example showing the usage |
|
18 of the LibpThread APIs. This example also shows how multi-threading is used |
|
19 to achieve concurrency in tasks and sharing of resources. </p> |
|
20 <section id="GUID-026FD8D6-6C4A-5958-B289-775D4AE1E756"><title>Download</title> <p>Click |
|
21 on the following link to download the example: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/zips/guid-84e8baf2-57f1-4255-aeb8-a6ed0ed2145e.zip" scope="external"> LibpThreadExample.zip</xref></p><p>Click: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/guid-84e8baf2-57f1-4255-aeb8-a6ed0ed2145e.html" scope="peer">browse</xref> to view the example code. </p> </section> |
|
22 <section><title>Description</title> <p>The following sections provide more |
|
23 information about the steps that the example performs. </p> <p><b> Thread |
|
24 Synchronisation</b> </p> <p>The example creates three threads named ThreadOne, |
|
25 ThreadTwo and ThreadThree. The threads write "One", "Two" and "Three" five |
|
26 times in a text file. The text file, located in <filepath>epoc32\winscw\c\newfile.txt</filepath>, |
|
27 is used as a shared resource for all three threads. A mutex is used to ensure |
|
28 that first ThreadOne writes in the file, then ThreadTwo and then ThreadThree. |
|
29 If the mutex is not used all the threads can simultaneously write in the file. |
|
30 This can be seen by commenting out <codeph>pthread_mutex_lock</codeph> and <codeph>pthread_mutex_unlock</codeph> in |
|
31 the code. </p> </section> |
|
32 <section><title>Related APIs</title><p><xref href="GUID-736D5209-CD86-324C-BAB0-7B15C3D1862D.dita"><apiname>pthread_mutex_lock</apiname></xref> </p><p><xref href="GUID-9D7CD10C-F958-3792-8888-B7F39B148302.dita"><apiname>pthread_mutex_unlock</apiname></xref> </p><p><xref href="GUID-3A89E849-DD7F-3381-9469-6CD89892E616.dita"><apiname>pthread_join</apiname></xref></p><p><xref href="GUID-889CB456-6980-3B92-9350-0C6C8C9AC435.dita"><apiname>pthread_mutex_t</apiname></xref></p></section> |
|
33 <section><title>Build</title> <p>The <xref href="GUID-3100800B-B2F7-50EF-BD4C-3C345ECCB2A5.dita">Symbian |
|
34 OS build process</xref> describes how to build this example application. </p> <p>The |
|
35 example builds an executable called <filepath>LibpThreadExample.exe</filepath> in |
|
36 the standard locations. </p> <p>To run the example, start <filepath>LibpThreadExample.exe</filepath> from |
|
37 the file system or from your IDE. After launching the executable, depending |
|
38 on the emulator you are using, you may need to navigate away from the application |
|
39 launcher or shell screen to view the console. </p> </section> |
|
40 </conbody></concept> |