首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >_beginthread/ex C3861 -找不到标识符

_beginthread/ex C3861 -找不到标识符
EN

Stack Overflow用户
提问于 2013-06-12 23:06:19
回答 5查看 3.2K关注 0票数 1

以下是我的测试代码

代码语言:javascript
复制
#include "stdafx.h"
#include "windows.h"
#include "iostream" 
using namespace std;

HANDLE hMutex;

static unsigned __stdcall threadFunc(void *params)
{
    WaitForSingleObject(hMutex,INFINITE);
    printf(":D:D:D\n");
    ReleaseMutex(hMutex);
    return NULL;    
}

int _tmain(int argc, _TCHAR* argv[])
{
        hMutex=CreateMutex(NULL,FALSE,NULL);
        //first try
        unsigned dwChildId;
        _beginthreadex(NULL, 0, &threadFunc, NULL, 0, &dwChildId);
        //second try
        _beginthread(threadFunc, 0, NULL );
        WaitForSingleObject(hMutex,INFINITE);
        printf("HD\n");
        ReleaseMutex(hMutex);
        int i;
        cin >> i;
    return 0;
}

给了我两个错误:

代码语言:javascript
复制
Error   1   error C3861: '_beginthreadex': identifier not found 
Error   2   error C3861: '_beginthread': identifier not found   

我使用MFC作为共享DLL。我也不知道如何创建两个具有相同功能的线程。

在我添加了“process.h”之后

代码语言:javascript
复制
Error   2   error C2664: '_beginthread' : cannot convert parameter 1 from 'unsigned int (__stdcall *)(void *)' to 'void (__cdecl *)(void *)'    
EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2013-06-12 23:27:17

_beginthread_beginthreadex需要不同类型的函数。_beginthread需要cdecl函数;_beginthreadex需要stdcall函数。

在x86上,cdecl和stdcall是不同的,您不能同时对_beginthread_beginthreadex使用单线程过程(在x64和ARM上,只有一个调用约定,所以stdcall和cdecl的含义是相同的,不是必需的)。

也就是说:不要使用_beginthread。相反,使用_beginthreadex,并确保关闭它返回的句柄。The documentation充分解释了_beginthread的缺点以及_beginthreadex更可取的原因。

票数 2
EN

Stack Overflow用户

发布于 2013-06-12 23:12:12

你是missing the appropriate header and/or you're not using the multithreaded C run-time libraries

代码语言:javascript
复制
/* Routine: _beginthreadex
 * Required header: process.h
 */
#include <process.h>
票数 1
EN

Stack Overflow用户

发布于 2013-06-12 23:12:58

docs建议它在process.h中,所以您需要

代码语言:javascript
复制
#include <process.h>

请注意,""会搜索到<>的不同路径

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17068914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档