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. Multithreading

Multithreading

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
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.
  • A Offline
    A Offline
    AdvancedCPP
    wrote on last edited by
    #1

    I am creating an application that is multithreaded and all the threads are accessing the same shared memory. The data coming into the memory should be processed in sequential order. Like if 1,2,3,4,5 comes in the memory then it should be processed in same order. I have used critical section around my memory, but I still get into a race condition where data is not grabbed by the thread in sequential order. Am I missing anything else to prevent threads from race condition? Thanks. ACpp

    N P 2 Replies Last reply
    0
    • A AdvancedCPP

      I am creating an application that is multithreaded and all the threads are accessing the same shared memory. The data coming into the memory should be processed in sequential order. Like if 1,2,3,4,5 comes in the memory then it should be processed in same order. I have used critical section around my memory, but I still get into a race condition where data is not grabbed by the thread in sequential order. Am I missing anything else to prevent threads from race condition? Thanks. ACpp

      N Offline
      N Offline
      Newbie00
      wrote on last edited by
      #2

      if you want to manage the order of working threads you have to use something to tell them, if it's their turn to work. critical sections are for keeping common data thread safe. Only one thread can enter critical section at given time. but there are no rules which thread can do it in cs case. It depends on system and threads state. If you want to set order you can use WaitForSingleObject or WaitForMultipleObjects with SetEvent method to let threads work when it's their time.

      1 Reply Last reply
      0
      • A AdvancedCPP

        I am creating an application that is multithreaded and all the threads are accessing the same shared memory. The data coming into the memory should be processed in sequential order. Like if 1,2,3,4,5 comes in the memory then it should be processed in same order. I have used critical section around my memory, but I still get into a race condition where data is not grabbed by the thread in sequential order. Am I missing anything else to prevent threads from race condition? Thanks. ACpp

        P Offline
        P Offline
        Pablo Aliskevicius
        wrote on last edited by
        #3

        Yes, you are. Google 'multi thread patterns'. It is a long path, but when you arrive, you're likely to feel it was worth it.

        Pablo. "Accident: An inevitable occurrence due to the action of immutable natural laws." (Ambrose Bierce, circa 1899).

        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