




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 45862-2025锅炉碳排放测试与计算方法
- 2023工作场所空气中环氧乙烷、环氧丙烷和环氧氯丙烷的溶剂解吸-气相色谱法
- 主题5 散装“苏超”火爆出圈-2026年高考语文之素材积累
- 雨铃铛教学设计
- 阅读理解-2024年高中英语学业水平考试考点归纳与测试(江苏专用)原卷版
- 单板加工职业技能认证体系可持续发展研究考核试卷
- 口碑营销对品牌忠诚度培养的作用机制研究考核试卷
- 情境模拟培训法考核试卷
- 安全事件应急响应的心理应激反应研究与应对策略考核试卷
- 风险教育与培训体系完善企业风险预防策略制定考核试卷
- 2025年贵州安大航空锻造有限责任公司-企业报告(业主版)
- 设计总监协议书
- 河北省廊坊市三河市2025届物理八下期末考试模拟试题含解析
- 2025软科学计划研究项目申报书
- 电网工程设备材料信息参考价2025年第一季度
- 贷款押金合同协议书范本
- 社保补助协议书范本
- 内分泌性高血压筛查专家共识(2025版)
- 关键岗位廉洁从业培训
- GB 5009.247-2025食品安全国家标准食品中纽甜的测定
- 防电气线路老化不规范
评论
0/150
提交评论