nachos01

相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

实验一体验Nachos下的并发程序设计

一、小组成员及分工

汪于波(23020078104116):的修改、的修改和实验报告

潘羽龙(23020078104100):的实现

吴道裕(23020078104132):的实现和实验报告的完成

谭原(23020078104111):dllist.h的实现和mon的修改

二、实验目的

对nachos进行熟悉,并初步体验nachos下的并发程序设计。

三、实验内容

1.安装nachos;

2.用C++实现双向有序链表;

3.在nachos系统中使用你所写的链表程序并演示一些并发错误

四、实验步骤

1.首先明确Nachos各部分的关系

在~/nachos/nachos-3.4/code/下有一个mon,在code/的各个子目录下的Makefile都继承这个mon。通过阅读知道,main函数一旦启动,立即调用Initialize,进行初始化的操作,然后对相应的参数进行处理,之后在分模块进行相应模块下的函数调用,执行相应的功能。

2.编写相应的函数

实验要求利用对双向链表的操作来演示并发程序可能出现的错误,首先需要实现双向链表dllist,包括dllist.h,。当DLList类实现后,需要编写链表驱动函数Insert 和Remove来对链表进行驱动。通过改写,使得多个线程在没有进行任何互斥操作的情况下对同一数据结构进行操作,在这个过程中就可能出现并发错误。改写mon和。

3.详细设计

a)dllist.h(~/nachos/nachos-3.4/code/threads/)

类DLList的声明

class DLLElement {

public:

DLLElement(void *itemPtr,int sortKey);//initialize a list element

DLLElement *next;//next element on list

DLLElement *prev;//previous element on list

int key;

void *item;

};

class DLList {

public:

DLList();//initialize the list

DLList(int type);

~DLList();//de-allocate the list

void Prepend(void *item);//add to head of list

void Append(void *item);//add to tail of list

void *Remove(int *keyPtr);//remove frome head of list

bool IsEmpty();//return true if list has elements

void SortedInsert(void *item,int sortKey);

void *SortedRemove(int sortKey);//remove first item with key==sortKey private:

DLLElement *first;

DLLElement *last;

int yield_type;//different yield positon

};

b) (~/nachos/nachos-3.4/code/threads/)

类DLList方法的实现,其中核心操作Remove,SortedInsert。

//---------------------------------------------------------------------- // DLList::Remove

// Remove the first "item" from the front of the dllist.

//

// Returns:

// Pointer to removed item, NULL if nothing on the list.

//---------------------------------------------------------------------- void *

DLList::Remove(int *keyPtr)

{

DLLElement *temp;

void *tempitem = NULL;

if(IsEmpty()) {

keyPtr = NULL;

}else {

*keyPtr = first->key;

if(yield_type == 1)

currentThread->Yield(); //the 1th positon of yield ****(1)

//the returned tempitem may not the item we just removed!

//the item maybe incorrect

tempitem = first->item;

temp = first;

first = first->next;

if(first != NULL) {

if(yield_type == 2)

currentThread->Yield(); //the 2th positon of yield ****(2)

//the dllist may lose its item

first->prev = NULL;

}else last = NULL;

}

delete temp;

相关文档
最新文档