http://blog.sina.com.cn/u/5438469990

nachos3.4 threads管理 (c++)

Main.cc

//引导代码初始化操作系统内核。允许直接调用内部操作系统功能,简化调试和测试。在实践中,bootstrap代码只会初始化数据结构,

//并启动一个用户程序来打印登录提示。//许多内容只有在分配之后才是需要的。
(比如说在线程管理中,我们只定义了THREAD,这样文件系统等相关信息就不会被执行)

// Usage: nachos -d <debugflags> -rs <random seed #>
//  -s -x <nachos file> -c <consoleIn> <consoleOut>
//  -f -cp <unix file> <nachos file>
//  -p <nachos file> -r <nachos file> -l -D -t
//              -n <network reliability> -m <machine id>
//              -o <other machine id>
//              -z
//
//    -d causes certain debugging messages to be printed (cf. utility.h)
//    -rs causes Yield to occur at random (but repeatable) spots
//    -z prints the copyright message
//
//  USER_PROGRAM
//    -s causes user programs to be executed in single-step mode
//    -x runs a user program
//    -c tests the con

-d  与调试信息相关,如果执行时增加参数 -d -t 则是打印出和thread相关的调试信息,如果执行时增加参数 -d + 则打印出所有调试信息。否则不打印。
-d  所跟的参数代表了需要打印哪些相关参数(具体见utility.h)
-rs 在指定的范围内随机触发线程的Yield方法,让出cpu,这个范围就是-rs 之后跟的参数(个人理解,不一定对)
-z  打印版本信息

之后都是与 USER_PROGRAM,FILESYS,NETWORK相关的内容,现在先不考虑

//  FILESYS
//    -f causes the physical disk to be formatted
//    -cp copies a file from UNIX to Nachos
//    -p prints a Nachos file to stdout
//    -r removes a Nachos file from the file system
//    -l lists the contents of the Nachos directory
//    -D prints the contents of the entire file system
//    -t tests the performance of the Nachos file system
//
//  NETWORK
//    -n sets the network reliability
//    -m sets this machine's host id (needed for the network)
//    -o runs a simple test of the Nachos network software
//
//  NOTE -- flags are ignored until the relevant assignment.
//  Some of the flags are interpreted here; some in system.cc.
//
// Copyright (c) 1992-1993 The Regents of the University of California.
// All rights reserved.  See copyright.h for copyright notice and limitation
// of liability and disclaimer of warranty provisions.

#define MAIN
#include "copyright.h"
#undef MAIN

#include "utility.h"
#include "system.h"

#ifdef THREADS
extern int testnum;
#endif

// External functions used by this file

extern void ThreadTest(void), Copy(char *unixFile, char *nachosFile);
extern void Print(char *file), PerformanceTest(void);
extern void StartProcess(char *file), ConsoleTest(char *in, char *out);
extern void MailTest(int networkID);

#ifdef THREADS
extern int testnum;
#endif
由于现在分析的是线程管理过程,我们在Makefile中只定义了THREADS
DEFINES = -DTHREADS
所以将会定义参数testnum,用来记录测试的线程数。
在额外函数中,我们只调用了如下函数,该函数在threadtest.cc 文件中,执行一个线程测试。
extern void ThreadTest(void)

//----------------------------------------------------------------------
// main
// 	Bootstrap the operating system kernel.  
//	
//	Check command line arguments
//	Initialize data structures
//	(optionally) Call test procedure
//
//	"argc" is the number of command line arguments (including the name of the command) -- ex: "nachos -d +" -> argc = 3 
//	"argv " is an array of strings, one for each command line argument  ex: "nachos -d +" -> argv = {"nachos", "-d", "+"}
//----------------------------------------------------------------------

 

int
main(int argc, char **argv)
{
    int argCount;            // the number of arguments 
                    // for a particular command

    DEBUG('t', "Entering main");
    (void) Initialize(argc, argv);
    
#ifdef THREADS
    for (argc--, argv++; argc > 0; argc -= argCount, argv += argCount) {
      argCount = 1;
      switch (argv[0][1]) {
      case 'q':
        testnum = atoi(argv[1]);
        argCount++;
        break;
      default:
        testnum = 1;
        break;
      }
    }

    ThreadTest();
#endif

 

posted @ 2018-02-24 16:16  Bob·li  阅读(229)  评论(0编辑  收藏  举报