Vikram Ranabhatt
Vikram Ranabhatt

Reputation: 7620

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);                                                                                                                                             
if ( NULL == m_hRecordImageThread)
{
   return;
} 
int CServerConnectionMgr::StreamImageThread(void *args)
{   

    IMAGETHREADINFO *pImageThreadInfo = (IMAGETHREADINFO*)&args;

}
  1. This is variable pImageThreadInfo->nSock showing some garbage value
  2. This pImageThreadInfo->pConMgr is coming correctly

I this is showing wrong value

Upvotes: 1

Views: 84

Answers (1)

Erik
Erik

Reputation: 91270

(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 &

Upvotes: 2

Related Questions