杭州电子科技大学操作系统课程设计——基于 DOS 的多任务系统的实现
运行环境:TC2.0+
(因为时间关系,我没有写缓冲队列的消息通信,有需要的同学请参考其它资料)
#include<stdio.h>
#include <stdlib.h>
#include <dos.h>
/*线程的四个状态*/
#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; /*最大线程数 , 阻塞队列头指针*/
评论0