您的位置:首页 > 其它

操作系统课程设计 -nachos- lab-new1

2017-11-24 19:43 337 查看
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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: