Symbian3/SDK/Source/GUID-9BFF0271-F5C3-45B6-AD4D-9179107F300A.dita
author Dominic Pinkman <dominic.pinkman@nokia.com>
Fri, 11 Jun 2010 12:39:03 +0100
changeset 8 ae94777fff8f
parent 7 51a74ef9ed63
child 13 48780e181b38
permissions -rw-r--r--
Week 23 contribution of SDK documentation content. See release notes for details. Fixes bugs Bug 2714, Bug 462.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept id="GUID-9BFF0271-F5C3-45B6-AD4D-9179107F300A" xml:lang="en"><title>Open
C Producer Consumer Example</title><prolog><metadata><keywords/></metadata></prolog><conbody>
<p>OpenCProducerConsumerEx is a 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 <codeph>libc</codeph> and <codeph>libpthread</codeph> </p>
<section id="GUID-026FD8D6-6C4A-5958-B289-775D4AE1E756-GENID-1-10-1-11-1-1-5-1-3-1-11-1-13-1-2-2"><title>Download</title> <p>Click
on the following link to download the example: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/zips/guid-b9259541-c444-400a-8f6e-8daaa5381a79.zip" scope="external">opencproducerconsumerex.zip</xref></p><p>Click: <xref href="guid-6013a680-57f9-415b-8851-c4fa63356636/guid-b9259541-c444-400a-8f6e-8daaa5381a79.html" scope="peer">browse</xref> to view the example code. </p> </section>
<section id="GUID-7E7C4564-B10E-41F9-8A9D-D8A6C5E9C51C-GENID-1-10-1-11-1-1-5-1-3-1-11-1-13-1-2-3"><title>Design and
Implementation</title> <p>The following sections provide information about
the implementation of the example. </p> <p><b>Capabilities</b> </p> The program
capability is defined in: <filepath>ProducerConsumer.mmp</filepath> (EXE -
application):<codeph> CAPABILITY NONE</codeph>. <p><b>Implementation details
of EXE</b> </p>This is a simple console based application. Main thread of
the application will create a thread named as Producer that will produce the
item and push it on to the stack. There will be N consumers which want to
consume some N(i) items from the Producer. Producer will produce N items at
a time and pushes them to the stack and totally it will produce sum(N(i))
items. The consumer thread will try to pop items from the stack and each consumer
will pop N(i) items from the stack. The application will create one thread
for each consumer. Producer and all the consumer threads will be synchronized
using a semaphore. The main thread, Producer and the consumer codes are pure
C-code. the stack used by Producer and the consumer threads is Standard C++
code. Apart from these threads, there is another thread named as Observer
that is created using Symbian platform API. Producer and the consumers will
establish a message queue with this thread and Observer will read message
from all other threads and will log them to a file wich is opened/written
using Symbian APIs. Hence, this application is a hybrid application with:
 <p>Standard C code -&gt; <filepath>Consumer.c</filepath>, <filepath>Producer.c</filepath>, <filepath>ProducerConsumer.c</filepath>, <filepath>CommanHeader.h</filepath> </p><p>Standard C++ code -&gt; <filepath>Stack.cpp</filepath>,<filepath>Stack.h</filepath>, <filepath>CommanHeader.h</filepath></p><p>Symbian
platform code that uses <codeph>libc</codeph> APIs and Observer.cpp.</p><p> 
The application has its own icon and can be launched from the UI both in the
emulator and in the device. </p><p><b>API Usage</b></p><p><codeph>string APIs</codeph> </p><p><codeph>IPC
APIs (message queue and semaphore)</codeph> </p><p> <codeph>Threading APIs
(from pthread)</codeph> </p><p><codeph>console I/O APIs</codeph>  </p><p><codeph>File
APIs of Symbian platform</codeph></p><p> <codeph>Threading APIs of Symbian
platform</codeph></p></section>
<section id="GUID-67A72761-1D92-46D1-B1C9-7455978BDE4E-GENID-1-10-1-11-1-1-5-1-3-1-11-1-13-1-2-4"><title>Building and
Using</title> To build the OpenCProducerConsumerEx application, go to the
OpenCProducerConsumerEx\group directory and build the application. The definition
for the whole application can be found in the<filepath> bld.inf</filepath>in
the group subdirectory of the applications main directory. <p>The application
is simple console based application. It has its own default icon and can be
launched from the UI both in the emulator and in the device. The application
can be launched by: Executing OpenCProducerConsumerEx from eshell. Clicking
default icon with display text OpenCProducerConsumerEx within the install
folder launcher application. </p></section>
</conbody></concept>