操作系统课程设计 -nachos- lab-new1
来源:互联网 发布:霍启山评价郭晶晶 知乎 编辑:程序博客网 时间:2024/06/05 19:13
nachos的奇奇怪怪的问题太多了,我预测到之后肯定会有好多学弟学妹来问,所以直接放上来存这算了哈哈哈哈~
The main.cc program of Nachos in ../threads/ calls function ThreadTest() as follows:
void
ThreadTest()
{
DEBUG(’t’, "Entering SimpleTest");
Thread *t = new Thread("forked thread");
t->Fork(SimpleThread, 1);
SimpleThread(0);
}
The SimpleThread() function used above is as follows:
void
SimpleThread(_int which)
{
int num;
for (num = 0; num < 5; num++) {
printf("*** thread %d looped %d times\n", (int) which, num);
currentThread->Yield();
}
}
Your tasks of this lab session is to
1. trace the execution of Nachos and observe the executions of
(a) context switch function SWITCH()
(b) function ThreadRoot()
using gdb and
第一个问题,在SWITCH()和ThreadRoot()初加断点,查看程序的运行情况。
程序在在主线程0被第一次执行后触发了断点1,即SWITCH()处的断点,再继续continue的时候可以看到发生了上下文切换,每次在跳过断点1的时候都会发生上下文切换。而断点2则只触发了一次。其中SWITCH()的作用就是进行上下文切换,而ThreadRoot()则是在线程被第一次创建的时候被调用,因而在线程1被创建时触发断点2,且该线程被创建后执行就不用再触发ThreadRoot()处的断点。
2. answer the following questions:
(a) What are the addresses of the following functions in your Nachos:
i. InterruptEnable()
ii. SimpleThread()
iii. ThreadFinish()
iv. ThreadRoot()
and describe how did you find them.
给上面提到的函数增加断点,即可以通过断点的位置判断出以上函数的地址。Where
地址如下:
1. InterruptEnable() 0x0804a300 thread.cc:242
2.SimpleThread() 0x0804a4b1 threadtest.cc:29
3.ThreadFinish() 0x0804a2e6 thread.cc:241
4.ThreadRoot() 0x0804bb06
(b) What are the addresses of the thread objects for
i. the main thread of the Nachos
主线程是在main函数里被创建的,因而找到主线程的地址需要给main函数加断点,通过step向下逐渐运行找到currentThread = new Thread(“main”);说明在该处主线程被创建,这是打印currentThread的地址,就是主线程的地址
ii. the forked thread created by the main thread
and describe how did you find them.
主线程是在ThreadTest中被创建的,找到Thread *t= new Thread(“forked thread”);
此时线程1被创建,打印出t的地址,就是该线程地址。
(c) When the main thread executes SWITCH() function for the first time, to what address
the CPU returns when it executes the last instruction ret of SWITCH()? What
location in the program that address is referred to?
题目中问主线程的SWITCH()断点最后一条汇编指令返回的地址,首先给SWITCH()设定断点,在主线程里进入SWITCH(),用ni指令向下执行下一条汇编指令,直到SWITCH执行结束。当主线程第一次执行SWITCH()时,CPU 执行SWITCH()的最后一条返回指令时将返回的地址是0x0804bb02。这个地址指向的是ThreadRoot()
(d) When the forked thread executes SWITCH() function for the first time, to what
address the CPU returns when it executes the last instruction ret of SWITCH()?
What location in the program that address is referred to?
当forked thread线程执行SWITCH()时,CPU 执行SWITCH()的最后一条返回指令时将返回的地址是0x0804914d。这个地址指向的是DEBUG()
- 操作系统课程设计 -nachos- lab-new1
- 操作系统课程设计实验3 -nachos-Synchronization Using Semaphores
- Nachos 课程设计task1.1
- nachos课程设计 task1.2
- Nachos课程设计Task1.3
- Nachos课程设计task1.4
- new1
- new1
- 操作系统Nachos实验
- nachos操作系统初步认识
- nachos操作系统pro1测试方法
- 模拟的操作系统nachos解读
- 操作系统课程设计
- 操作系统课程设计
- 操作系统课程设计
- 操作系统课程设计
- 操作系统课程设计
- 操作系统课程设计
- 用JavaScript面向对象画一个三角形
- Xcode9 iOS11适配 iPhoneX适配 heightForHeaderInSection、contentInset失效解决 contentInsetAdjustmentBehavior详解
- SVN Update Error: Please execute the 'Cleanup' command
- struts与spring集成
- python查看和更改当前工作目录
- 操作系统课程设计 -nachos- lab-new1
- 使用宏定义定义π的值,输出球的体积和表面积,球的半径r由键盘输入!
- 小结二
- 【软件架构】通俗易懂的MVP架构讲解
- ssm 日期参数报400问题--自定义日期转换类
- 微信小程序中使用路由
- PhpStorm中如何使用database工具
- Aop 面向切面编程
- c语言5.2.c