Nokia N97 SDK
Example Applications Guide

Producer Consumer Problem Solution Example

1. About this Example
2. Prerequisites
3. Design and Implementation


1. About this Example

OpenCProducerConsumerEx is Hybrid Application that depicts solution for Producer Consumer Problem using Open C. This application uses main() as an entry point for the application. It uses libc and libpthread


1.1 APIs used


1.2 Building and Using

To build the OpenCProducerConsumerEx application, go to the OpenCProducerConsumerEx\group directory and build the application.


2. Prerequisites

This example requires a familiarity with the C/C++ programming language, and access to the Open C stanadard library documentation. As, this example uses Open C Standard library, the reader is recommended to read the following topics from the Open C SDK documentation before proceeding:

As its a hybrid application, one should be having fair knowledge of Symbian C++ also


3. Design and Implementation

3.1 Capabilities

The program capability is defined in:

ProducerConsumer.mmp file (EXE - application): CAPABILITY NONE.

3.2 Implementation details of Application

The application is simple console based application. Main thread of Application will create one Producer thraed that will produce the item and push it on to Stack. There will be some N consumers each want to consume some N(i) items from Producer. Producer will Produce N items at a time and pushes them to Stack and totally it will produce SUM(N(i)) items. Consumer will try to Pop items from Stack and each consumer will Pop N(i) items from Stack.

Application will create one thread from each Consumer. Procuder and all the Consumers will be synchronized using semaphore.

Main thread, Producer and Consumer codes are pure C-code. Stack used by Producer and Consumer is Standard C++ code (Not Symbian C++ Code)

Apart from these threads, there will be one thread, Observer that is created using Symbian APIs. Producer and Consumers will establish a message queue with this thread and Observer will read message from all other threads and will log them to File wich is opened/written using Symbian APIs.

So, This application is one Hybrid application with:

  1. Standard C code -> Consumer.c, Producer.c, ProducerConsumer.c, CommanHeader.h
  2. Standard C++ code -> Stack.cpp, Stack.h, CommanHeader.h
  3. Symbian C++ code that uses libc apis also -> Observer.cpp

It has its own icon and can be launched from the UI both in the emulator and in the device.


© Nokia 2009

Back to top