📄 node32.html
字号:
<html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><!--Converted with jLaTeX2HTML 2002 (1.62) JA patch-1.4patched version by: Kenshi Muto, Debian Project.LaTeX2HTML 2002 (1.62),original version by: Nikos Drakos, CBLU, University of Leeds* revised and updated by: Marcus Hennecke, Ross Moore, Herb Swan* with significant contributions from: Jens Lippmann, Marek Rouchal, Martin Wilck and others --><HTML><HEAD><TITLE>4.2 Schedulers and Events</TITLE><META NAME="description" CONTENT="4.2 Schedulers and Events"><META NAME="keywords" CONTENT="everything"><META NAME="resource-type" CONTENT="document"><META NAME="distribution" CONTENT="global"><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"><META NAME="Generator" CONTENT="jLaTeX2HTML v2002 JA patch-1.4"><META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css"><LINK REL="STYLESHEET" HREF="everything.css" tppabs="http://www.isi.edu/nsnam/ns/doc/everything.css"><LINK REL="next" HREF="node38.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node38.html"><LINK REL="previous" HREF="node31.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node31.html"><LINK REL="up" HREF="node30.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node30.html"><LINK REL="next" HREF="node33.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node33.html"></HEAD><BODY ><!--Navigation Panel--><A NAME="tex2html1810" HREF="node33.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node33.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1804" HREF="node30.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node30.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html1798" HREF="node31.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node31.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1806" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html1808" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html1811" HREF="node33.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node33.html">4.2.1 The List Scheduler</A><B> Up:</B> <A NAME="tex2html1805" HREF="node30.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node30.html">4. The Class Simulator</A><B> Previous:</B> <A NAME="tex2html1799" HREF="node31.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node31.html">4.1 Simulator Initialization</A>   <B> <A NAME="tex2html1807" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1809" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <BR><BR><!--End of Navigation Panel--><H1><A NAME="SECTION03120000000000000000"></A><A NAME="sec:sched"></A><BR>4.2 Schedulers and Events</H1><P>The simulator is an event-driven simulator.There are presently four schedulers available in the simulator, eachof which is implemented using a different data structure:a simple linked-list, heap, calendar queue (default), and a specialtype called ``real-time''. Each of these are described below.The scheduler runs by selecting the next earliest event, executingit to completion, and returning to execute the next event.Unit of time used by scheduler is seconds.Presently, the simulator is single-threaded, and only one eventin execution at any given time.If more than one event are scheduled to execute at the same time,their execution is performed on the first scheduled - firstdispatched manner. Simultaneous events are not re-ordered anymore byschedulers (as it was in earlier versions) and all schedulers shouldyeild the same order of dispatching given the same input.<P>No partial execution of events or pre-emption is supported.<P>An <EM>event</EM> generally comprises a ``firing time'' and a handler function.The actual definition of an event is found in scheduler.h:<PRE> class Event { public: Event* next_; /* event list / Handler* handler_; /* handler to call when event ready / double time_; /* time at which event is ready / int uid_; /* unique ID / Event() : time_(0), uid_(0) {} }; /* * The base class for all event handlers. When an event's scheduled * time arrives, it is passed to handle which must consume it. * {\ie, if it needs to be freed it, it must be freed by the handler.} */ class Handler { public: virtual void handle(Event* event); };</PRE>Two types of objects are derived from the baseEvent../ns-2/scheduler.cc: packets and ``at-events''.Packets are described in detail in the next chapterChaptersec:packetclass.An at-event is a tcl procedure execution scheduled to occur ata particular time. This is frequently used in simulation scripts.A simple example of how it is used is as follows:<PRE> \ldots set ns_ [new Simulator] $ns_ use-scheduler Heap $ns_ at 300.5 "$self complete_sim" \ldots</PRE>This tcl code fragment first creates a simulation object,then changes the default scheduler implementation to be heap-based(see below), and finally schedules the function <TT>$self complete_sim</TT>to be executed at time 300.5 (seconds)(Note that this particular code fragment expects to be encapsulated in an object instance procedure, where the appropriatereference to <TT>$self</TT> is correctly defined.).At-events are implemented as events where the handler iseffectively an execution of the tcl interpreter.<P><BR><HR><!--Table of Child-Links--><A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A><UL><LI><A NAME="tex2html1812" HREF="node33.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node33.html">4.2.1 The List Scheduler</A><LI><A NAME="tex2html1813" HREF="node34.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node34.html">4.2.2 the heap scheduler</A><LI><A NAME="tex2html1814" HREF="node35.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node35.html">4.2.3 The Calendar Queue Scheduler</A><LI><A NAME="tex2html1815" HREF="node36.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node36.html">4.2.4 The Real-Time Scheduler</A><LI><A NAME="tex2html1816" HREF="node37.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node37.html">4.2.5 Precision of the scheduler clock used in ns</A></UL><!--End of Table of Child-Links--><HR><!--Navigation Panel--><A NAME="tex2html1810" HREF="node33.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node33.html"><IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next" SRC="file:/usr/share/latex2html/icons/next.png"></A> <A NAME="tex2html1804" HREF="node30.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node30.html"><IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up" SRC="file:/usr/share/latex2html/icons/up.png"></A> <A NAME="tex2html1798" HREF="node31.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node31.html"><IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous" SRC="file:/usr/share/latex2html/icons/prev.png"></A> <A NAME="tex2html1806" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html"><IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents" SRC="file:/usr/share/latex2html/icons/contents.png"></A> <A NAME="tex2html1808" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html"><IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index" SRC="file:/usr/share/latex2html/icons/index.png"></A> <BR><B> Next:</B> <A NAME="tex2html1811" HREF="node33.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node33.html">4.2.1 The List Scheduler</A><B> Up:</B> <A NAME="tex2html1805" HREF="node30.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node30.html">4. The Class Simulator</A><B> Previous:</B> <A NAME="tex2html1799" HREF="node31.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node31.html">4.1 Simulator Initialization</A>   <B> <A NAME="tex2html1807" HREF="node1.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node1.html">Contents</A></B>   <B> <A NAME="tex2html1809" HREF="node590.html" tppabs="http://www.isi.edu/nsnam/ns/doc/node590.html">Index</A></B> <!--End of Navigation Panel--><ADDRESS>2003-09-23</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -