1.为什么不能跨线程使用百度了一下,说是tls机制导致的, 为什么这个类是tls类,就不能跨线程使用它?2. 谁提供一个范例,如何修改,在线程里使用这个类?有人会说,从线程参数穿进去不久可以了嘛?不行! 原因 这个线程负责和七八个客户端通信。 接受数据,我怎么传,传的是哪一个?
服务端启东,线程就开启了, 就等着收数据,如果从AfxBeginThread传,岂不是逻辑不对乎?所以我没法从参数哪里穿进去啊
服务端启东,线程就开启了, 就等着收数据,如果从AfxBeginThread传,岂不是逻辑不对乎?所以我没法从参数哪里穿进去啊
解决方案 »
- 求数据采集程序
- 用CreateProcess调用一个命令行工具时出现This application has requested the Runtime...
- CVSFlexGrid问题
- list控件为什么无法显示数据库中内容
- webbrowser打开word后的问题
- 给定窗体的句柄,如何知道该窗体是否有状态栏?
- help me!(编字处理软件高手请进好吗?)
- 这是是么意思??
- 如何改进,以加快速度?????
- 在VC++中,如何判断注册表里是否存在某个子键?谢谢!
- DLL 本地定义符号*****在函数****中导入
- LoadBitmapW怎么动态加载图片资源,即用先在图片资源里load,而直接加载图片文件名
SYMPTOMS
When using MFC sockets in secondary threads in a statically linked MFC Visual C++ 6.0 application, an unhandled exception occurs. CAUSE
The reason for the unhandled exception is that an object of type CMapPtrToPtr pointer, pointed to by m_pmapSocketHandle, is never created. RESOLUTION
The handle maps used by the sockets need to be created for each thread. The following code shows a function to do this: void SocketThreadInit()
{
#ifndef _AFXDLL
#define _AFX_SOCK_THREAD_STATE AFX_MODULE_THREAD_STATE
#define _afxSockThreadState AfxGetModuleThreadState() _AFX_SOCK_THREAD_STATE* pState = _afxSockThreadState;
if (pState->m_pmapSocketHandle == NULL)
pState->m_pmapSocketHandle = new CMapPtrToPtr;
if (pState->m_pmapDeadSockets == NULL)
pState->m_pmapDeadSockets = new CMapPtrToPtr;
if (pState->m_plistSocketNotifications == NULL)
pState->m_plistSocketNotifications = new CPtrList; #endif
}
This function should be called once in each secondary thread before the first socket is created in the new thread. STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.This bug was corrected in Visual Studio 6.0 Service Pack 3. You will need to call AfxSocketInit() in each thread that uses sockets. For more information about Visual Studio service packs, please see the following articles in the Microsoft Knowledge Base:
Q194022 INFO: Visual Studio 6.0 Service Packs, What, Where, Why
Q194295 HOWTO: Tell That Visual Studio 6.0 Service Packs Are Installed MORE INFORMATION
In MFC socket applications, AfxSocketInit is called once, by default, in the primary thread. This function creates the handle maps for the primary thread when statically linked to MFC. However, when a secondary thread is created, these per-thread handle maps are not created. AfxSocketInit must be called in each thread to initialize the socket libraries.
Steps to Reproduce Behavior
1. Create an application that creates a socket in a secondary thread and uses MFC in a static link library. You can use the MultiSoc sample described in the following Knowledge Base article by changing the project settings to use MFC in a static library:
Q175668 FILE: MultiSoc: Illustrates Using Sockets in Multiple Threads
2. Run the application and create a socket in a secondary thread.REFERENCES
For additional information, please see the following article in the Microsoft Knowledge Base:
Q175668 FILE: MultiSoc: Illustrates Using Sockets in Multiple Threads © Microsoft Corporation 1998, All Rights Reserved.
Contributions by Isaac L. Varon, Microsoft Corporation
Additional query words: LookupHandle CAsyncSocket AttachHandle GetValueAt assert wincore.cpp 980 Application Error 0xc0000005 m_pHashTable CSocket access violation debug assertion failed
Keywords : kbMFC kbVC600bug kbWinsock kbVS600sp3fix kbGrpDSMFCATL kbNoUpdate
Issue type : kbbug
Technology : kbAudDeveloper kbMFC