⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node62.html

📁 Design and building parallel program
💻 HTML
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
<!Converted with LaTeX2HTML 95.1 (Fri Jan 20 1995) by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds >
<HEAD>
<TITLE>5.11 Case Study: Channel Library</TITLE>
</HEAD>
<BODY>
<meta name="description" value="5.11 Case Study: Channel Library">
<meta name="keywords" value="book">
<meta name="resource-type" value="document">
<meta name="distribution" value="global">
<P>
 <BR> <HR><a href="msgs0.htm#2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#2"><img ALIGN=MIDDLE src="asm_color_tiny.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/asm_color_tiny.gif" alt="[DBPP]"></a>    <A NAME=tex2html2679 HREF="node61.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node61.html"><IMG ALIGN=MIDDLE ALT="previous" SRC="previous_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/previous_motif.gif"></A> <A NAME=tex2html2687 HREF="node63.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node63.html"><IMG ALIGN=MIDDLE ALT="next" SRC="next_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/next_motif.gif"></A> <A NAME=tex2html2685 HREF="node51.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node51.html"><IMG ALIGN=MIDDLE ALT="up" SRC="up_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/up_motif.gif"></A> <A NAME=tex2html2689 HREF="node1.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node1.html"><IMG ALIGN=MIDDLE ALT="contents" SRC="contents_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/contents_motif.gif"></A> <A NAME=tex2html2690 HREF="node133.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node133.html"><IMG ALIGN=MIDDLE ALT="index" SRC="index_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/index_motif.gif"></A> <a href="msgs0.htm#3" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#3"><img ALIGN=MIDDLE src="search_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/search_motif.gif" alt="[Search]"></a>   <BR>
<B> Next:</B> <A NAME=tex2html2688 HREF="node63.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node63.html">5.12 Case Study: Fock Matrix Construction</A>
<B>Up:</B> <A NAME=tex2html2686 HREF="node51.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node51.html">5 Compositional C++
 </A>
<B> Previous:</B> <A NAME=tex2html2680 HREF="node61.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node61.html">5.10 Performance Issues</A>
<BR><HR><P>
<H1><A NAME=SECTION032110000000000000000>5.11 Case Study: Channel Library</A></H1>
<P>
<A NAME=secccchan>&#160;</A>
<P>
In the first of two more substantial examples, we present an
implementation of the channel library used in
<A NAME=7689>&#160;</A>
Program <A HREF="node53.html#progccbuild" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node53.html#progccbuild">5.3</A>.  This case study illustrates how
<A NAME=7691>&#160;</A>
CC++
  can be used to develop libraries implementing particular programming
paradigms: in this case, channel communication.
<P>
<P><A NAME=8556>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img864.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img864.gif">
<BR><STRONG>Figure 5.8:</STRONG> <em> Data structures used in the CC++
  channel library.
In addition to a queue, a channel comprises an <tt> OutPort</tt> object
and an <tt> InPort</tt> object used to encapsulate pointers to the queue.
Processes apply send and receive operations to the outport and inport,
respectively.</em><A NAME=figccchan>&#160;</A><BR>
<P>
<P>
The channel library provides functions to create a channel, to extract
pointers to inport and outport structures, and to send and receive
messages.  A channel is constructed from three basic data structures:
the message queue itself and outport and inport objects used to
contain pointers to the queue (Figure <A HREF="node62.html#figccchan" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node62.html#figccchan">5.8</A>).  The outport
is created in the same processor object as the sender, while the
inport and message queue are created in the same processor object as
the receiver.
<P>
The implementation, Program <A HREF="node62.html#progccq" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node62.html#progccq">5.15</A>, defines the processor
object <tt> ChannelUser</tt> and the classes <tt> Channel</tt>, <tt> InPort</tt>,
and <tt> OutPort</tt>.  The processor object provides functions <tt>
create_inport</tt> and <tt> create_outport</tt> that create the inport and
outport associated with a channel; any program wanting to use the
channel library must include this processor object as a base class.
Recall that this was done when defining the processor object <tt>
Construction</tt> in Program <A HREF="node53.html#progccbuild" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node53.html#progccbuild">5.3</A>.
<P>
The <tt> Channel</tt> class provides three public member functions: the
constructor <tt> Channel</tt>, which creates a new channel linking two
specified processor objects; <tt> get_out_port</tt>, which returns a
pointer to the channel's outport; and <tt> get_in_port</tt>, which
returns a pointer to the channel's inport.
<P>
<P><A NAME=progccq>&#160;</A><IMG BORDER=0 ALIGN=BOTTOM ALT="" SRC="img865.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/img865.gif"><P>
<P>
The <tt> InPort</tt> class is derived from the <tt> Queue</tt> class of
Program <A HREF="node56.html#progccch0" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node56.html#progccch0">5.6</A>.  It adds to the functions already defined
in that class a new function <tt> receive</tt>, which simply dequeues a
message from the queue.  Finally, the <tt> OutPort</tt> class encapsulates
a global pointer and provides a <tt> send</tt> function that invokes an
<tt> enqueue</tt> operation on the message queue referenced by this
pointer.
<P>

<BR> <HR><a href="msgs0.htm#2" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#2"><img ALIGN=MIDDLE src="asm_color_tiny.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/asm_color_tiny.gif" alt="[DBPP]"></a>    <A NAME=tex2html2679 HREF="node61.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node61.html"><IMG ALIGN=MIDDLE ALT="previous" SRC="previous_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/previous_motif.gif"></A> <A NAME=tex2html2687 HREF="node63.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node63.html"><IMG ALIGN=MIDDLE ALT="next" SRC="next_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/next_motif.gif"></A> <A NAME=tex2html2685 HREF="node51.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node51.html"><IMG ALIGN=MIDDLE ALT="up" SRC="up_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/up_motif.gif"></A> <A NAME=tex2html2689 HREF="node1.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node1.html"><IMG ALIGN=MIDDLE ALT="contents" SRC="contents_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/contents_motif.gif"></A> <A NAME=tex2html2690 HREF="node133.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node133.html"><IMG ALIGN=MIDDLE ALT="index" SRC="index_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/index_motif.gif"></A> <a href="msgs0.htm#3" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#3"><img ALIGN=MIDDLE src="search_motif.gif" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/search_motif.gif" alt="[Search]"></a>   <BR>
<B> Next:</B> <A NAME=tex2html2688 HREF="node63.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node63.html">5.12 Case Study: Fock Matrix Construction</A>
<B>Up:</B> <A NAME=tex2html2686 HREF="node51.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node51.html">5 Compositional C++
 </A>
<B> Previous:</B> <A NAME=tex2html2680 HREF="node61.html" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/node61.html">5.10 Performance Issues</A>
<BR><HR><P>
<P><ADDRESS>
<I>&#169 Copyright 1995 by <A href="msgs0.htm#6" tppabs="http://www.dit.hcmut.edu.vn/books/system/par_anl/tppmsgs/msgs0.htm#6">Ian Foster</a></I>
</ADDRESS>
</BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -