D
David student
Guest
Hi,
We have the below code that was written using CreateThread.
HANDLE m_hReceiveThread ;
void CUPSData::createUPSThread()
{
m_hReceiveThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReceiveDataFromUPS,(LPVOID)this, NULL, NULL);
if (NULL != m_hReceiveThread)
{
printToUPSFile(UPS_LOG_INFO, " receive thread started");
}
else
{
printToUPSFile(UPS_LOG_ERROR, " Unable to start receive thread");
g_bUPSFail = true;
}
}
void CUPSData::ReceiveDataFromUPS(LPVOID f_data)
{
printToUPSFile(UPS_LOG_INFO, "Start");
CUPSData *l_hclassInstance = (CUPSData *)f_data;
f_data->receiveData();
}
I was asked to replace CreateThread with std::thread. Using std::thread, I am writing like as shown below:
std::thread(ReceiveDataFromUPS, this);
But, when replacing Windows CreateThread with std::thread, how to use the HANDLE (m_hReceiveThread) as this handle is using in many other places.
for eg, this handle is using in other function like (DWORD dwWaitResult = WaitForSingleObject(m_hReceiveThread, INFINITE);
Could someone please help me with their inputs?
Regards,
Continue reading...
We have the below code that was written using CreateThread.
HANDLE m_hReceiveThread ;
void CUPSData::createUPSThread()
{
m_hReceiveThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ReceiveDataFromUPS,(LPVOID)this, NULL, NULL);
if (NULL != m_hReceiveThread)
{
printToUPSFile(UPS_LOG_INFO, " receive thread started");
}
else
{
printToUPSFile(UPS_LOG_ERROR, " Unable to start receive thread");
g_bUPSFail = true;
}
}
void CUPSData::ReceiveDataFromUPS(LPVOID f_data)
{
printToUPSFile(UPS_LOG_INFO, "Start");
CUPSData *l_hclassInstance = (CUPSData *)f_data;
f_data->receiveData();
}
I was asked to replace CreateThread with std::thread. Using std::thread, I am writing like as shown below:
std::thread(ReceiveDataFromUPS, this);
But, when replacing Windows CreateThread with std::thread, how to use the HANDLE (m_hReceiveThread) as this handle is using in many other places.
for eg, this handle is using in other function like (DWORD dwWaitResult = WaitForSingleObject(m_hReceiveThread, INFINITE);
Could someone please help me with their inputs?
Regards,
Continue reading...