📄 real-time experiment #2 multi-tasking.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0066)http://www.rt.db.erau.edu/experiments/vx/tasking/Experiment-2.html -->
<HTML><HEAD><TITLE>Real-Time Experiment #2: Multi-Tasking</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<BODY>
<CENTER>
<H1>Embry-Riddle Real-Time Laboratory Experiment<BR>Experiment
#2<BR>Multi-Tasking </H1></CENTER>
<HR SIZE=3>
<H2>Introduction</H2>Modern real-time systems are based on the complementary
concepts of multitasking and intertask communications. A multitasking
environment allows real-time applications to be constructed as a set of
independent tasks, each with a separate thread of execution and its own set of
system resources. The intertask communication facilities allow these tasks to
synchronize and coordinate their activities.
<P></P>The VxWorks multitasking kernel, <EM>wind</EM>, uses interrupt-driven,
priority- based task scheduling. It features fast context switch time and low
interrupt latency.
<P></P>
<HR SIZE=3>
<H2>Objectives</H2>The following are the primary objectives of this experiment:
<UL>
<LI>To teach the student how to initiate multiple processes using Vxworks
tasking routines. </LI></UL>
<P></P>
<HR SIZE=3>
<H2>Description</H2>Multitasking creates the appearance of many threads of
execution running concurrently when, in fact, the kernel interleaves their
execution on a basis of ascheduling algorithm. Each apparently independent
program is called a <EM>task</EM>. Each task has its own <EM>context</EM>, which
is the CPU environment and system resources that the task sees each time it is
scheduled to run by the kernel.
<P></P>On a <EM>context switch</EM>, a task's context is saved in the <EM>Task
Control Block</EM>(TCB). A task's context includes:
<P></P>
<UL>
<LI>a thread of execution, that is, the task's program counter
<LI>the CPU registers and floating-point registers if necessary
<LI>a stack of dynamic variables and return addresses of function calls
<LI>I/O assignments for standard input, output, error
<LI>a delay timer
<LI>a timeslice timer
<LI>kernel control structures
<LI>signal handlers
<LI>debugging and performance monitoring values </LI></UL>1. Task Creation and
Activation
<P></P>The routine <EM>taskSpawn</EM> creates the new task context, which
includes allocating and setting up the task environment to call the main
routine(an ordinary subroutine) with the specified arguments. The new task
begins at the entry to the specified routine.
<P></P>The arguments to <EM>taskSpawn()</EM> are the new task's name(an ASCII
string), priority, an "options" word(also hex value), stack size(int), main
routine address(also main routine name), and 10 integer arguments to be passed
to the main routine as startup parameters.
<P></P>2. Syntax
<P></P><EM>id</EM> = taskSpawn(<EM>name,priority,options,stacksize,function,
arg1,..,arg10);</EM>
<P></P>3. Example
<P></P>This example creates ten tasks which all print their task Id once: <PRE>---------------------------------------------------------------------------
#define ITERATIONS 10
void print(void);
spawn_ten() /* Subroutine to perform the spawning */
{
int i, taskId;
for(i=0; i < ITERATIONS; i++) /* Creates ten tasks */
taskId = taskSpawn("tprint",90,0x100,2000,print,0,0,0,0,0,0,0,0,0,0);
}
void print(void) /* Subroutine to be spawned */
{
printf("Hello, I am task %d\n",taskIdSelf()); /* Print task Id */
}
---------------------------------------------------------------------------
</PRE>
<HR SIZE=3>
<H2>Procedures</H2>1. Copy the source code in the example and compile it.
<P></P>2. Load the object file onto the target machine.
<P></P>3. Run the example by executing "spawn_ten" on the WindSh.
<P></P>Note: Make sure you have redirected I/O, otherwise you won't see the
results of the printf commands.
<HR SIZE=3>
<H2>Follow On Experiment</H2>As shown in the example, the task creation process
allows the passing of ten arguments to the <EM>function</EM>.
<P></P>Experiment 1. As discussed above, up to a ten integer arguments can be
passed to a task during the call to <EM>taskSpawn()</EM>. Pass a unique argument
to each of the ten tasks and have them print it. For example, pass the increment
variable "i" in subroutine spawn_ten().
<P></P>Experiment 2. Assign each task a unique priority. Is there any difference
in output? Has the order in which the ten tasks print changed? If not, explain
why.
<P></P>
<HR SIZE=3>
<H2>Additional Information</H2>Refer to the VxWorks Programmer's Manual and
Reference Manual.
<HR SIZE=3>
<BR>
<CENTER>
<H4><A
href="http://www.rt.db.erau.edu/experiments/vx/toc/TableOfContents.html">Return
to Table of Contents </A></H4></CENTER><BR>
<CENTER>Last Updated: 17 March 1997<BR><EM>Created by: Dan Eyassu</EM><BR><A
href="mailto:eyassud@db.erau.edu">eyassud@db.erau.edu</A><BR></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -