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. <queue> queue threadsafe?

<queue> queue threadsafe?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
3 Posts 2 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
    Pixinger77
    wrote on last edited by
    #1

    Hi, I speak of the class std::queue / #include In my case the question is: 1. Is it safe to execute m_queue.push from thread A, while thread B executes m_queue.pop? 2. Is it safe to execute m_queue.push from thread A, while thread B executes m_queue.empty? 3. Is it safe to execute m_queue.push from thread A and also from thread B? I hope you understand what i mean, thanks in advance Snow.

    T 1 Reply Last reply
    0
    • P Pixinger77

      Hi, I speak of the class std::queue / #include In my case the question is: 1. Is it safe to execute m_queue.push from thread A, while thread B executes m_queue.pop? 2. Is it safe to execute m_queue.push from thread A, while thread B executes m_queue.empty? 3. Is it safe to execute m_queue.push from thread A and also from thread B? I hope you understand what i mean, thanks in advance Snow.

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      None of the STL objects are thread safe. Wrap the calls in critical sections. Tim Smith I'm going to patent thought. I have yet to see any prior art.

      P 1 Reply Last reply
      0
      • T Tim Smith

        None of the STL objects are thread safe. Wrap the calls in critical sections. Tim Smith I'm going to patent thought. I have yet to see any prior art.

        P Offline
        P Offline
        Pixinger77
        wrote on last edited by
        #3

        Thanks for your answer Tim. I found an MSDN article "Thread Safety in the Standard C++ Library" which statet that some of the STL container classes are threadsafe (but only in certain cases). But I think it will be better to write a wrapper for the queue class as you wrote before. It seems to be the only way to be on the safe side. Thanks, Snow.

        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