没有合适的资源?快使用搜索试试~ 我知道了~
操作系统实验-nachos01.doc
资源推荐
资源详情
资源评论
操作系统实验-nachos01
实验一 体验 Nachos 下的并发程序设计
一、实验人员:
二、实验目的:
对 nachos 进行熟悉,并初步体验 nachos 下的并发程序设计
三、实验内容:
1、安装 Nachos
2、用 C++实现双向有序链表;
3、在 nachos 系统中使用所写的链表程序并演示一些并发错误
四、实验步骤:
1、 安装 Nachos,具体细则如下
下载 code-linux.tar.gz 并上传到服务器
建立目录(推荐建立主目录下的 nachos)
cd 到新建目录中
tar zxvf code-linux.tar.gz 的完整路径
cd nachos-3.4/code
make
2、 阅读材料
阅读 nachos-3.4/code/Makefile
nachos-3.4/code/Makefile.dep
nachos-3.4/code/Makefile.common
nachos-3.4/code/threads/Makefile
初步了解各 Makefile 的构成和相互关系。
阅读 nachos-3.4/code/threads/main.cc 了解 nachos 如何开始。
阅读 nachos-3.4/code/threads/system.cc 的 Initialize 函数中与 debug 相关的部分及
nachos-3.4/code/threads/utility.cc 了解 DEBUG 的实现与使用,以此进一步熟悉
nachos 系统。
阅读 nachos-3.4/code/threads/threadtest.cc,了解 nachos 中线程的概念及其运作方
式。
3、 编写相关的 dllist.h,dllist.cc,dllist-driver.cc 文件,具体代码如下
dllist.h
class DLLElement {
public:
DLLElement( void *itemPtr, int sortKey ); // initialize a list element
DLLElement *next; // next element on list
// NULL if this is the last
DLLElement *prev; // previous element on list
// NULL if this is the first
int key; // priority, for a sorted list
操作系统实验-nachos01
void *item; // pointer to item on the list
};
class DLList {
public:
DLList(); // initialize the list
DLList(int type);
~DLList(); // de-allocate the list
void Prepend(void *item); // add to head of list (set key = min_key-1)
void Append(void *item); // add to tail of list (set key = max_key+1)
void *Remove(int *keyPtr); // remove from head of list
// set *keyPtr to key of the removed item
// return item (or NULL if list is empty)
bool IsEmpty(); // return true if list has elements
// routines to put/get items on/off list in order (sorted by key)
void SortedInsert(void *item, int sortKey);
void *SortedRemove(int sortKey); // remove first item with key==sortKey
// return NULL if no such item exists
private:
DLLElement *first; // head of the list, NULL if empty
DLLElement *last; // last element of the list, NULL if empty
int err_type;
};
Dllist.cc
#include "copyright.h"
#include "dllist.h"
#include "system.h"
DLLElement::DLLElement( void *itemPtr, int sortKey ) // initialize a list element
{
item=itemPtr;
key=sortKey;
next=NULL;
prev=NULL;
}
DLList::DLList() // initialize the list
{
first=NULL;
last=NULL;
err_type=0;
}
DLList::DLList(int type)
{
操作系统实验-nachos01
first=NULL;
last=NULL;
err_type=type;
}
DLList::~DLList() // de-allocate the list
{
while (Remove(NULL)!=NULL)
;
}
void DLList::Prepend(void *item) // add to head of list (set key = min_key-1)
{
DLLElement *elm=new DLLElement(item,0);
if (IsEmpty())
{
first=elm;
last=elm;
}
else
{
elm->key=first->key-1;
elm->next=first;
elm->prev=NULL;
first->prev=elm;
first=elm;
}
}
void DLList::Append(void *item) // add to tail of list (set key = max_key+1)
{
DLLElement *elm=new DLLElement(item,0);
if (IsEmpty())
{
first=elm;
last=elm;
}
else
{
elm->key=last->key+1;
elm->next=NULL;
elm->prev=last;
last->next=elm;
last=elm;
}
}
void *DLList::Remove(int *keyPtr) // remove from head of list
剩余12页未读,继续阅读
资源评论
是空空呀
- 粉丝: 171
- 资源: 3万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功