我遇到过这样的问题。 我有一个库,它允许通过UDP进程间通信。 它非常直截了当。该库创建可用于其他进程写入和读取的共享内存。当进程想要读取感兴趣的内存时,它会传递一个字符串值,该值唯一指向相应的共享内存,并将指针传递给容器(char数组),以便在此期间接收读取结果。图书馆提供安全的多线程。QThread和读取内存
当线程离开run()例程时,我有一个异常。
例外:访问冲突,它是在
void __cdecl _freeptd (
_ptiddata ptd
)
{
/*
* Do nothing unless per-thread data has been allocated for this module!
*/
if (__flsindex != 0xFFFFFFFF) {
/*
* if parameter "ptd" is NULL, get the per-thread data pointer
* Must NOT call _getptd because it will allocate one if none exists!
* If FLS_GETVALUE is NULL then ptd could not have been set
*/
if (ptd == NULL
#ifndef _M_AMD64
&& (FLS_GETVALUE != NULL)
#endif /* _M_AMD64 */
)
ptd = FLS_GETVALUE(__flsindex);
/*
* Zero out the one pointer to the per-thread data block
*/
FLS_SETVALUE(__flsindex, (LPVOID)0);
_freefls(ptd);
}
if (__getvalueindex != 0xFFFFFFFF) {
/*
* Zero out the FlsGetValue pointer
*/
TlsSetValue(__getvalueindex, (LPVOID)0);
}
}
代码提出:只有当我们允许library->readFromSharedMemory(struct_name, memory);
char* memory = new char(2000);
string struct_name = "struct";
bool m_running = false;
void Reader::run()
{
initalizeLibrary();
m_running = true;
//loop
while(true)
{
if (! m_running) break;
library->readFromSharedMemory(struct_name, memory);
}
finalize();
}
void Reader::stop()
{
m_running = false;
}
异常。 _freeptd
无法访问导致访问冲突的内存。
我需要一只手。 Thx提前。