Nokia N97 SDK Example Applications Guide |
Producer Consumer Problem Solution Example
1. About this Example
2. Prerequisites
3. Design and Implementation
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
- string apis
- ipc apis (message queue and semaphore)
- threading apis (from pthread)
- console I/O apis
- Symbian File APIs
- Symbian threading APIs
To build the OpenCProducerConsumerEx application, go to the OpenCProducerConsumerEx\group directory and build the application.
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:
- standard library how to
- descriptions on ipc apis
- descriptions on threading apis
As its a hybrid application, one should be having fair knowledge of Symbian C++ also
The program capability is defined in:
ProducerConsumer.mmp file (EXE - application): CAPABILITY NONE.
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:
- Standard C code -> Consumer.c, Producer.c, ProducerConsumer.c, CommanHeader.h
- Standard C++ code -> Stack.cpp, Stack.h, CommanHeader.h
- 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
|

|