【文件属性】:
文件名称:基于DOS的多任务系统
文件大小:105KB
文件格式:DOC
更新时间:2016-01-12 11:04:16
DOS 多任务系统
#include#include #include
/*线程的四个状态*/#define finished 0#define running 1#define ready 2#define blocked 3#define null 0#define NTCB 5 /*最大线程数为5*/
#define GET_INDOS 0x34#define GET_CRIT_ERR 0x5d06
#define TLE 1
#define n 5 /*buffer缓冲区大小*/int current,timecount; /*正在执行的线程内部标识符*/unsigned p;
char far *indos_ptr = 0;char far *crit_err_ptr = 0;
int buffer[n]; /*缓冲区*/int in = 0,out = 0; /*缓冲区下标*/
struct TCB{unsigned char *stack; /*堆栈的起始地址*/unsigned ss; /*堆栈段址*/unsigned sp; /*堆栈指针*/int state; /*进程状态*/char name[10]; /*线程的外部标识符*/unsigned prio; /*优先级*/struct TCB *next; /*指向下一个线程*/}tcb[NTCB],*head; /*最大线程数 , 阻塞队列头指针*/
struct int_regs /*现场信息的保存格式布置堆栈*/{unsigned bp, di, si, ds, es, dx, cx, bx, ax, ip, cs, flags;};
typedef struct{ /*记录型信号量*/int value;struct TCB *wq;}semaphore;semaphore mutex={1,NULL},emputy={n,NULL},full={0,NULL};
typedef void (far *codeptr)();
void tcb_state1(){int i;for (i=0 ; i<5 ; i++){ printf("%d thread = %d\n" , i , tcb[i].state);}}
void InitIndos(){/*函数名:InitIndos无参用途:初始化DOS*/union REGS regs;struct SREGS segregs;/*获得INDOS flag 的地址*/regs.h.ah=GET_INDOS;intdosx(®s;,®s;,&segregs;),indos_ptr=MK_FP(segregs.es,regs.x.bx);/*get the address of CRIT_ERR flag*/