Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 01:06, 2 October 2007.

How to communicate between two threads or processes

From Forum Nokia Wiki

Contents

Introduction

The following mechanisms are used to communicate between two threads within a process and also between unrelated processes(created either by a Symbian app or Open C application):

Pipes

Pipes can be used when a process creates child processes or threads and wants to communicate with them. The following steps are needed to do so:

  • Declare a global variable with array [2] of data type int.
  • Create a pipe.
  • Create a thread.
  • Read data from the pipe from the parent thread.
  • Write data from the child thread.
  • Close the read or write descriptor

Pipes Example

Named pipes

Named pipes(mkfifo) are used to communicate between threads within a process or between two unrelated processes. The following steps are needed to do so:

  • Create a named pipe using mkfifo.
  • Create a process or thread and open this pipe in write mode.
  • Another process or thread can open the same in read mode.
  • Close the read or write descriptor.

Named Pipes Example

Message queues

Message queues are used to communicate between threads within a process or two unrelated processes. The following steps are needed to do so:

  • Create a message queue using msgget.
  • Create a process or thread and send some message to this message queue.
  • Read the message from the main thread.
  • Delete the message queue.

Message Queues Example

Shared memory

Shared memory is used to communicate between threads within a process or two unrelated processes, allowing both to share a given region of memory. The following steps are needed to do so:

  • Create a shared memory segment using shmget<tt>.
  • Attach the segment to the address space of both processes using <tt>shmat.
  • Synchronize processes to correct access the shared memory.
  • Detach the shared memory segment from the address space of the processes using shmdt.

Shared Memory Example

Related Discussions
Thread Thread Starter Forum Replies Last Post
On device debugging Nokia phones skjolber Mobile Java General 5 2007-08-21 05:11
Threads vitormcruz General Symbian C++ 11 2007-08-22 20:46
Communicate with 3310 by AT Command tcwong3 General Messaging 0 2003-04-15 18:21
CMdaAudioInputStream mot working inside a thread symbiannil General Symbian C++ 1 2008-04-22 11:53
Difference between "Delete then Reset and "ResetAndDestroy"? julppoupou General Symbian C++ 0 2003-04-02 09:17
 
Powered by MediaWiki