summaryrefslogtreecommitdiff
path: root/docs/tutorials/010/page01.html
blob: 8e27323bd1a4344d2e1de26deabd3b0532ffe23e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="James CE Johnson">
   <TITLE>ACE Tutorial 010</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#000FFF" VLINK="#FF0F0F">

<CENTER><B><FONT SIZE=+2>ACE Tutorial 010</FONT></B></CENTER>

<CENTER><B><FONT SIZE=+2>Passing chunks of data through an ACE_Message_Queue</FONT></B></CENTER>


<P>
<HR WIDTH="100%">
<P>
In an earlier tutorial we briefly introduced ACE_Message_Queue.  In this
tutorial we'll go into a bit more detail.
<P>
ACE_Message_Queue is modeled after Unix System V IPC mechanisms.  The basic
idea is that you put a block of data into one end of the Queue and take it
out of the other end.  Your basic FIFO in other words.  The SysV mechanism
works great for passing these blocks of data between processes on the same
host but it's a bit overkill for moving blocks between threads.  You could
use a pipe, socket or similar mechanism but that still has more overhead than
we really want just for moving data between threads.  Process-global memory
is a good technique but then you need a way to signal the "listening" threads.
The ACE_Message_Queue is a better approach:  Create blocks of data and enqueue
them in one thread while another thread (or threads) dequeue and perform work.
<P>
Kirthika's Abstract:
<UL>
The Message Queue is a FIFO accessible from multiple threads.
That is, a thread puts the produced blocks of data on the message queue
to be consumed by some other thread/threads and processed. In this
tutorial, we see how effectively the Message Queue in a ACE_Task can be
used to pass data among threads in the thread pool. 
(this is very similar to 
<A HREF="../007/page01.html">Tutorial 7</A>
 wherein we implemented a
thread-pool server).Here, actual data is passed between the threads and
also an ACE_Barrier has been used to provide synchronisation among
multiple threads.
<P>
The Message Queue consists of Message Blocks, each of which has a read
and write pointer. Using these pointers the message blocks can be
accessed for reading and writing operations. The ACE_Task::svc() method
will put the block onto the queue without bothering about the existence 
of a consumer for that block. A thread from the thread pool obtains the
block from the queue, and checks to see whether the block_type is
MB_HANGUP. If so, it puts the block back on the queue for its 
peers and exits. Otherwise, it reads the block and processes it before
releasing it.
<P>
This simple tutorial makes us aware of the usage and importance of the
Message Queue which could be used to our advantage especially for
multithreaded applications.
</UL>
<P><HR WIDTH="100%">
<CENTER>[<A HREF="../online-tutorials.html">Tutorial Index</A>] [<A HREF="page02.html">Continue This Tutorial</A>]</CENTER>