Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Sharing object between thread

Sharing object between thread

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    packetlos
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • P packetlos

      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

      P Offline
      P Offline
      packetlos
      wrote on last edited by
      #2

      I solved this problem by placing a critical section around the usage of the instance of my class :)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups