CreateThread成功后,紧接CloseHandle,不解
SDK的文档中,
Multithreaded Pipe Server那节有个例子.
fConnected = ConnectNamedPipe(hPipe, NULL) ?
TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
if (fConnected)
{
// Create a thread for this client.
hThread = CreateThread(
NULL, // no security attribute
0, // default stack size
(LPTHREAD_START_ROUTINE) InstanceThread,
(LPVOID) hPipe, // thread parameter
0, // not suspended
&dwThreadId); // returns thread ID
if (hThread == NULL)
{
printf("CreateThread failed");
return 0;
}
else CloseHandle(hThread);
}
else
// The client could not connect, so close the pipe.
CloseHandle(hPipe);
}
在成功创建一个线程后就调用CloseHandle(hThread).
hThread在创建后,计数为1,CloseHandle后,计数为0,也就是说hThread被删掉了!
那么这么做有什么意义呢?帮忙解释,谢谢!
Multithreaded Pipe Server那节有个例子.
fConnected = ConnectNamedPipe(hPipe, NULL) ?
TRUE : (GetLastError() == ERROR_PIPE_CONNECTED);
if (fConnected)
{
// Create a thread for this client.
hThread = CreateThread(
NULL, // no security attribute
0, // default stack size
(LPTHREAD_START_ROUTINE) InstanceThread,
(LPVOID) hPipe, // thread parameter
0, // not suspended
&dwThreadId); // returns thread ID
if (hThread == NULL)
{
printf("CreateThread failed");
return 0;
}
else CloseHandle(hThread);
}
else
// The client could not connect, so close the pipe.
CloseHandle(hPipe);
}
在成功创建一个线程后就调用CloseHandle(hThread).
hThread在创建后,计数为1,CloseHandle后,计数为0,也就是说hThread被删掉了!
那么这么做有什么意义呢?帮忙解释,谢谢!
...全文
相关推荐
createthread函数用法详解
详细介绍了createthread函数 在程序中的运用 对于c++多线程的学习有很大帮助
Hibernate ORM框架中文参考指南
本文还有配套的精品资源,点击获取 简介:Hibernate是一个在Java开发中广泛使用的对象关系映射(ORM)框架,它使得开发者可以采用面向对象的方式来简化数据库操作。这本中文参考手册详细介绍了Hibernate的核心概念、配置、实体类映射、查询语言、缓存机制以及性能优化策略。手册还包括了NHibernate,即Hibernate在.NET平台上的等价物,让.NET开发者...
CreateThread函数创建窗口线程.rar_createthread_线程 窗口_线程函数
此代码是为初步接触多线程的人员介绍的用CreateThread()函数创建窗口线程。
CreateThread用法详解.doc
CreateThread用法详解.doc
C++ 中CloseHandle 函数–关闭一个句柄
CloseHandle函数 作用 关闭一个打开的对象句柄。 语法 BOOL WINAPI CloseHandle( _In_ HANDLE hObject ); 参数 hObject 已经打开的有效对象句柄。 返回值 如果函数操作成功,返回值为非零值 如果函数操作失败,返回值为零。 注意: (1)句柄不应该被关闭两次; (2)可以关闭的句柄有控制台输入、控制台屏幕缓冲区等。 头文件 Winbase..h(包括Windows.h) 参考来源:来源:https://msdn.microsoft.com/en-us/library/windows/desktop/ms724


进程/线程/DLL
