kvv*_*kvv 0 c++ winapi multithreading
我用vs2013编写了简单的代码,它的工作原理很奇怪:
#include <Windows.h>
#include <process.h>
#include <stdio.h>
#include <cstdint>
#include <tchar.h>
class A
{
public:
explicit A(uint8_t byte) : mByte(byte) {}
~A() { _tprintf(_T("A::~A(%x)\n"), mByte); }
private:
uint8_t mByte;
};
unsigned WINAPI threadRoutine(void*)
{
A a0(0x41);
_endthreadex(0);
return 0;
}
int _tmain(int argc, TCHAR *argv[])
{
HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, threadRoutine, NULL, 0, NULL);
WaitForSingleObject(hThread, INFINITE);
CloseHandle(hThread);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出为空,这意味着没有为局部变量a0调用A-dtor?
我的代码中是否有一些错误?
如果在函数返回后没有调用局部变量析构函数,如何在线程例程函数中维护RAII?
| 归档时间: |
|
| 查看次数: |
137 次 |
| 最近记录: |