turbo c多线程代码,储藏


#include<dos.h>
#include<stdio.h>
#include<stdlib.h>
extern void myprint(const char *str,int len);
typedef struct{
    int    r_bp;/*top of the stack*/
    int    r_di;
    int    r_si;
    int    r_ds;
    int    r_es;
    int    r_dx;
    int    r_cx;
    int    r_bx;
    int r_ax;
    int r_ip;
    int r_cs;
    int r_cflag;/*bottom of the stack,relatively speaking*/
}StackVal;
typedef enum{running=0x00,suspend,stop} State;
typedef struct{
    StackVal stackVal;
    State thrState;
}Thread;
typedef Thread TaskLine[3];
typedef struct{
    int id;
    TaskLine taskLine;
}TaskMan;
/*===============================================================*/
TaskMan taskMan;
union REGS in,out;
/*===============================================================*/
/*================================================================*/
void interrupt(*oldVect)(void); /*定义old_intlc为中断函数指针*/
void interrupt schedule(void);    /*自编的1CH中断服务程序*/
void func1(void);
void func2(void);
void initTMan();
/*================================================================*/
int main()
{
  asm cli
  printf("initializing.../n");
  oldVect=getvect(0x1c);  /*取原ICH中断向量*/
  setvect(0x1c,schedule);   /*置新的1CH中断向量*/
  initTMan();/*初始化线程控制队列*/
  printf("initializing done/n");
  asm sti
  for(;;)
  {
        /*printf("this is main routine!/n");*/
        if(bioskey(1)!=0)    /*按任一键,恢复原1CH中断向量,程序结束*/
        {
        setvect(0x1c,oldVect);
        exit(0);
        }

   }
    return 0;
}
void interrupt schedule(void)/*自编的1CH中断服务程序*/
{
 /* printf("scheduling.../n");*/
  /*from top to bottom*/
  /*bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flags*/
  /*since an automatic variable is defined, sp has been modified only bp is pointing to
    the effective top of the stack!
  */
  int r_sp;
  asm mov r_sp,ss:[bp+2]
  taskMan.taskLine[0].stackVal.r_bp = r_sp;
  /*memcpy(taskMan.taskLine[taskMan.id].stackVal,r_sp,sizeof(StackVal));*/
  taskMan.id =0x0001;/*(taskMan.id+1)%3;*/
  /*printf("scheduling done/n");*/
}
void initTMan()
{
    int i;
    memset(&taskMan,0xFF,sizeof(TaskMan));
    asm mov ax,cs
    for(i=0;i<3;i++){
    asm mov taskMan.taskLine[i].stackVal.r_cs,ax
    taskMan.taskLine[i].thrState = running;
    }
    taskMan.taskLine[1].stackVal.r_ip=(int)func1;
    taskMan.taskLine[2].stackVal.r_ip=(int)func2;
}
void func1()
{
    myprint("hello-",6);
}
void func2()
{
    myprint("helo+",6);
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值