×
Namespaces

Variants
Actions

How to communicate between two threads or processes

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: spark55 (01 Oct 2007)
Last edited: hamishwillee (27 Jul 2012)

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 style="font-family:monospace;">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

This page was last modified on 27 July 2012, at 08:16.
370 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×