Thread Argument Problem
I have working on multithreaded application I am passing IMAGETHREADINFO
structure in thread here nSock
is showing garbage value. What is the problem here.pointer to IMAGETHREADINFO
is declared as member variable of CServerConnectionMgr
class.
typedef struct
{
int nScok;
CServerConnectionMgr* pConMgr;
}IMAGETHREADINFO;
void StartImageThread(SOCKET nSock)
{
stThreadInfo = new IMAGETHREADINFO;
stThreadInfo.pConMgr = this;
stThreadInfo.nScok = nSock;
m_hRecordImageThread = CreateThread ( NULL,0, (LPTHREAD_START_ROUTINE)StreamImageThread,(void*)&stThreadInfo, 0,&m_nRecordImageThreadID); 开发者_StackOverflow
if ( NULL == m_hRecordImageThread)
{
return;
}
int CServerConnectionMgr::StreamImageThread(void *args)
{
IMAGETHREADINFO *pImageThreadInfo = (IMAGETHREADINFO*)&args;
}
- This is variable
pImageThreadInfo->nSock
showing some garbage value - This
pImageThreadInfo->pConMgr
is coming correctly
I this is showing wrong value
(void*)&stThreadInfo
is a pointer to the stThreadInfo
pointer. You likely want to remove the &
And then, also change IMAGETHREADINFO *pImageThreadInfo = (IMAGETHREADINFO*)&args;
, remove the &
精彩评论