Sharing object between thread
-
I am having a problem with threads and wonder if anybody can help, I am spawning a worker thread that updates a linked list that I need access to from the other thread, basically i am passing the instance of the class with the linked list using a struct:
UINT CNetworkMonitoringDoc::CaptureThread(LPVOID pParam) { THREADPARMS* ptp = (THREADPARMS*) pParam; CPacket* m_capturedPacket = ptp->pPacketInst; delete ptp; ... }
The worker thread adds data to the linked list ok but when the orginal thread needs to do something with the m_capturedPacket instance the contained linked list is empty, im guessing the thread is creating its own private copy and working on that; is there anyway to share m_capturedPacket between them? Cheers Andy -
I am having a problem with threads and wonder if anybody can help, I am spawning a worker thread that updates a linked list that I need access to from the other thread, basically i am passing the instance of the class with the linked list using a struct:
UINT CNetworkMonitoringDoc::CaptureThread(LPVOID pParam) { THREADPARMS* ptp = (THREADPARMS*) pParam; CPacket* m_capturedPacket = ptp->pPacketInst; delete ptp; ... }
The worker thread adds data to the linked list ok but when the orginal thread needs to do something with the m_capturedPacket instance the contained linked list is empty, im guessing the thread is creating its own private copy and working on that; is there anyway to share m_capturedPacket between them? Cheers Andy