多线程的创建以及VC6.0下的编译设置.doc_第1页
多线程的创建以及VC6.0下的编译设置.doc_第2页
多线程的创建以及VC6.0下的编译设置.doc_第3页
多线程的创建以及VC6.0下的编译设置.doc_第4页
多线程的创建以及VC6.0下的编译设置.doc_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

多线程的创建 以及VC6.0下的编译设置示例一:#include #include using namespace std;DWORD WINAPI FunOne(LPVOID param)while(1) Sleep(300); coutThis is FunOne.endl;return 1;DWORD WINAPI FunTwo(LPVOID param)while(1) Sleep(300); coutThis is FunTwo.endl;return 1;int main(int argc,char * argv)DWORD lp1=0,lp2=0;HANDLE hand1=CreateThread(NULL,0,FunOne,NULL,CREATE_SUSPENDED,&lp1);HANDLE hand2=CreateThread(NULL,0,FunTwo,NULL,CREATE_SUSPENDED,&lp2);/system(pause);Sleep(2000);ResumeThread(hand1);ResumeThread(hand2);/system(pause);Sleep(6000);return 0;/*线程占用输出缓冲出现的问题This is FunOne.This is FunTwo.This is FunTwoThis is FunOne.This is FunTwThis is FunOne.o.This is FunOThis is FunTwo.ne.This is FunThis is FunOne.Two.This is FuThis is FunTwo.nOne.This is FThis is FunTwo.unOne.This is This is FunOne.FunTwo.This isThis is FunTwo.FunOne.This iThis is FunOne.s FunTwo.This This is FunTwo.is FunOne.ThisThis is FunOne.is FunTwo.ThiThis is FunTwo.s is FunOne.ThThis is FunOne.is is FunTwo.This is FunOne.This is FunTwo.This is FunOne.This is FunTwo.This is FunOne.This is FunTwo.This is FunOne.This is FunTwo.This is FunOne.This is FunTwo.Press any key to continue*/示例二:#include /#define MT/#define _MT#include #include using namespace std;void ThreadFunc1(PVOID param)Sleep(1000);coutThis is ThreadFunc1endl;void ThreadFunc2(PVOID param)Sleep(2000);coutThis is ThreadFunc2endl;int main()int i=0;_beginthread(ThreadFunc1,0,NULL);_beginthread(ThreadFunc2,0,NULL);Sleep(3000);coutendendl;_endthread();return 0;/*This is ThreadFunc1This is ThreadFunc2endPress any key to continue*/示例二的代码在VC6.0的默认设置下编译出错:d:c+osmulti thread 2.cpp(22) : error C2065: _beginthread : undeclared identifierd:c+osmulti thread 2.cpp(26) : error C2065: _endthread : undeclared identifier打开 process.h 发现如下代码段:#ifdef _MT_CRTIMP unsigned long _cdecl _beginthread (void (_cdecl *) (void *), unsigned, void *);_CRTIMP void _cdecl _endthread(void);_CRTIMP unsigned long _cdecl _beginthreadex(void *, unsigned, unsigned (_stdcall *) (void *), void *, unsigned, unsigned *);_CRTIMP void _cdecl _endthreadex(unsigned);#endif表示如果定义了 _MT(multi thread) 才会包含_beginthread 等函数的声明于是尝试在process.h之前定义一个 _MT (代码中红色注释部分),结果出现了如下错误:multi thread 2.obj : error LNK2001: unresolved external symbol _endthreadmulti thread 2.obj : error LNK2001: unresolved external symbol _beginthreadlibcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol _unlocklibcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol _locklibcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol _setlc_activelibcpmtd.lib(xmbtowc.obj) : error LNK2001: unresolved external symbol _unguarded_readlc_active【错误原因分析】简单的define _MT 是包含了_beginthread等函数的声明,但是编译器并不会调用相关的dll(包含上述声明实现的函数)参与linking,所以出现了上述那么多未解决的外部标识符。【解决办法】编译器设置步骤如下: 工程 属性 C/C+ 分类:Code Gen

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论