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. Accessing data between threads

Accessing data between threads

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
3 Posts 3 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.
  • L Offline
    L Offline
    ledallam
    wrote on last edited by
    #1

    -------------------------------------------------------------------------------- Hello, I am writing an application which uses two threads. I have a list variable in my Document class. THREAD 1 In this thread, I am filling a list from back i.e pDoc->list.insert(list.begin(),data); THREAD 2 In this thread, I am extracting each element from top of the list, and displaying it on the UserInterface i.e data = pDoc->list.pop_front(); Display(data); THREAD1 cotinously reads and adds data at the bottom of the list while THREAD 2 gets data from the top of the list and displays it. Can I directly access the list memeber available in my document class as above in the two threads. When I tried the above, it worked fine when the list had limited number say 10 to 30 records, but as the size of list was growing to say 10,000 records the program was crashing. Can anyone please help me to solve this ? Thanks Madhavi

    A H 2 Replies Last reply
    0
    • L ledallam

      -------------------------------------------------------------------------------- Hello, I am writing an application which uses two threads. I have a list variable in my Document class. THREAD 1 In this thread, I am filling a list from back i.e pDoc->list.insert(list.begin(),data); THREAD 2 In this thread, I am extracting each element from top of the list, and displaying it on the UserInterface i.e data = pDoc->list.pop_front(); Display(data); THREAD1 cotinously reads and adds data at the bottom of the list while THREAD 2 gets data from the top of the list and displays it. Can I directly access the list memeber available in my document class as above in the two threads. When I tried the above, it worked fine when the list had limited number say 10 to 30 records, but as the size of list was growing to say 10,000 records the program was crashing. Can anyone please help me to solve this ? Thanks Madhavi

      A Offline
      A Offline
      Arsalan Malik
      wrote on last edited by
      #2

      Your problem is that, you are using a shared resource (list) between two threads. You need synchronization between threads, so that only one thread at at time can access shared list. To achieve this, you can use CEvent, CMutex, or CSemaphore, depending on your needs and choice. See any good reference on these classes.:cool: ARSALAN MALIK

      1 Reply Last reply
      0
      • L ledallam

        -------------------------------------------------------------------------------- Hello, I am writing an application which uses two threads. I have a list variable in my Document class. THREAD 1 In this thread, I am filling a list from back i.e pDoc->list.insert(list.begin(),data); THREAD 2 In this thread, I am extracting each element from top of the list, and displaying it on the UserInterface i.e data = pDoc->list.pop_front(); Display(data); THREAD1 cotinously reads and adds data at the bottom of the list while THREAD 2 gets data from the top of the list and displays it. Can I directly access the list memeber available in my document class as above in the two threads. When I tried the above, it worked fine when the list had limited number say 10 to 30 records, but as the size of list was growing to say 10,000 records the program was crashing. Can anyone please help me to solve this ? Thanks Madhavi

        H Offline
        H Offline
        Hardy_Smith
        wrote on last edited by
        #3

        You can also try to use thread-save lists. I think there are some at www.stlport.org. Hardy.

        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