私はそのような問題に直面しました。UDP プロセス間通信を許可するライブラリがあります。それは非常に簡単です。ライブラリは、他のプロセスが読み書きできる共有メモリを作成します。プロセスが関心のあるメモリを読み取りたい場合、対応する共有メモリを一意に指す文字列値を渡し、読み取りの結果を受け取ることが期待されるコンテナー (char 配列) へのポインターを渡します。ライブラリは安全なマルチスレッドを提供します。
スレッドが 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);
}
}
コード:
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;
}
を許可した場合にのみ例外が発生しlibrary->readFromSharedMemory(struct_name, memory);
ます。_freeptd
アクセス違反の原因となるメモリにアクセスできません。
手が必要です。事前にThx。