LibpThread Example - Using P.I.P.S OECORE

This example application shows, using a P.I.P.S. (P.I.P.S. Is POSIX on the Symbian platform) program, the use of the LibpThread library to demonstrate simple multi-threading and synchronisation.

The purpose is to create a basic multithreading example showing the usage of the LibpThread APIs. This example also shows how multi-threading is used to achieve concurrency in tasks and sharing of resources.

Download

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

Click: browse to view the example code.

Description

The following sections provide more information about the steps that the example performs.

Thread Synchronisation

The example creates three threads named ThreadOne, ThreadTwo and ThreadThree. The threads write "One", "Two" and "Three" five times in a text file. The text file, located in epoc32\winscw\c\newfile.txt, is used as a shared resource for all three threads. A mutex is used to ensure that first ThreadOne writes in the file, then ThreadTwo and then ThreadThree. If the mutex is not used all the threads can simultaneously write in the file. This can be seen by commenting out pthread_mutex_lock and pthread_mutex_unlock in the code.

Related APIs

pthread_mutex_lock(pthread_mutex_t *)

pthread_mutex_unlock(pthread_mutex_t *)

pthread_join(pthread_t,void **)

pthread_mutex_t

Build

The Symbian build process describes how to build this example application.

The example builds an executable called LibpThreadExample.exe in the standard locations.

To run the example, start LibpThreadExample.exe from the file system or from your IDE. After launching the executable, depending on the emulator you are using, you may need to navigate away from the application launcher or shell screen to view the console.