C如何创建一个线程

czcwzw 2010-10-29 05:15:47
我用的编译器是turbo c,请问如何创建一个线程?
...全文
247 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
傻X 2010-10-29
  • 打赏
  • 举报
回复
上段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);
}

BIN307 2010-10-29
  • 打赏
  • 举报
回复
看孙兴的视频,里面说的很详细。
xili 2010-10-29
  • 打赏
  • 举报
回复
没听说 tubor c 可以写win32的应用.
我印象中 tubor c 是dos程序. dos没有线程.
yiyilove97 2010-10-29
  • 打赏
  • 举报
回复
createprocessthread 不知道在你的环境中能用不
Eleven 2010-10-29
  • 打赏
  • 举报
回复
#include <process.h>

_beginthreadex()?
野男孩 2010-10-29
  • 打赏
  • 举报
回复
没试过。。。

如果可以的话,应该include <process.h>,然后调用_beginthread
沙鹰 2010-10-29
  • 打赏
  • 举报
回复
TC能实现多线程吗?
wltg2001 2010-10-29
  • 打赏
  • 举报
回复
tc能调用API吗?
ouyh12345 2010-10-29
  • 打赏
  • 举报
回复
创建线程得利用系统api
ouyh12345 2010-10-29
  • 打赏
  • 举报
回复
_beginthread

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧