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. ATL / WTL / STL
  4. Please enlighten me on STL iterators and CriticalSection locking

Please enlighten me on STL iterators and CriticalSection locking

Scheduled Pinned Locked Moved ATL / WTL / STL
c++performancequestion
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.
  • K Offline
    K Offline
    Kosta Cherry
    wrote on last edited by
    #1

    I use STL at work, but "lazy" way, i.e. it works, and who cares about performance, right :)? So I know only basics about STL. Now I'm currently writing heavily multithreaded program for my own good. For the sake of fast development at this stage I opted to use STL. And then I noticed during debugging, that STL iterators call Critical Section locking, which causes a lot of slow down. I then delved (very briefly) into STL code and saw that they are really using CS for the iterators. I immediately dropped STL from the project, thanks to the fact that I use only arrays, not lists or maps, and there are plenty straight-forward-no-hidden-things implementations of templated arrays out there. But now I'm curious: when exactly STL iterators use CS locking? Is it for non-const iterators only? Is it for in-between-threads access? Or always? I'm too lazy and too busy to dive deep into STL code to check this, and it's not relevant to the project anymore, but out of curiosity it is very interesting, and might be useful for others who strive for performance and use STL. Thank you in advance! P.S. Forgot to mention: I use MS implementation of STL (VC++ 2005). SY- Kosta.

    A 1 Reply Last reply
    0
    • K Kosta Cherry

      I use STL at work, but "lazy" way, i.e. it works, and who cares about performance, right :)? So I know only basics about STL. Now I'm currently writing heavily multithreaded program for my own good. For the sake of fast development at this stage I opted to use STL. And then I noticed during debugging, that STL iterators call Critical Section locking, which causes a lot of slow down. I then delved (very briefly) into STL code and saw that they are really using CS for the iterators. I immediately dropped STL from the project, thanks to the fact that I use only arrays, not lists or maps, and there are plenty straight-forward-no-hidden-things implementations of templated arrays out there. But now I'm curious: when exactly STL iterators use CS locking? Is it for non-const iterators only? Is it for in-between-threads access? Or always? I'm too lazy and too busy to dive deep into STL code to check this, and it's not relevant to the project anymore, but out of curiosity it is very interesting, and might be useful for others who strive for performance and use STL. Thank you in advance! P.S. Forgot to mention: I use MS implementation of STL (VC++ 2005). SY- Kosta.

      A Offline
      A Offline
      Andy Moore
      wrote on last edited by
      #2

      As far as I know STL does not do any critical section locking as that is left up to the application developer. We use STL (STLPort) extensively for high-performance server-side applications and find its performance outstanding. As far as thread safety goes I would look at the Adapative Communication Framework (ACE). This library has reader/writer locks so readers don't block each other accessing a cache but a write blocks all readers. If you have a cache that is primarily read-only then this is quite and efficient mechanism.

      Pax Domini sit semper vobiscum

      K 1 Reply Last reply
      0
      • A Andy Moore

        As far as I know STL does not do any critical section locking as that is left up to the application developer. We use STL (STLPort) extensively for high-performance server-side applications and find its performance outstanding. As far as thread safety goes I would look at the Adapative Communication Framework (ACE). This library has reader/writer locks so readers don't block each other accessing a cache but a write blocks all readers. If you have a cache that is primarily read-only then this is quite and efficient mechanism.

        Pax Domini sit semper vobiscum

        K Offline
        K Offline
        Kosta Cherry
        wrote on last edited by
        #3

        I think I (almost) found answer to my own question. Here is code: #if _HAS_ITERATOR_DEBUGGING void _Orphan_range(pointer _First, pointer _Last) const { // orphan iterators within specified (inclusive) range _Lockit _Lock(_LOCK_DEBUG); const_iterator **_Pnext = (const_iterator **)&this->_Myfirstiter; while (*_Pnext != 0) if ((*_Pnext)->_Myptr < _First || _Last < (*_Pnext)->_Myptr) _Pnext = (const_iterator **)&(*_Pnext)->_Mynextiter; else { // orphan the iterator (*_Pnext)->_Mycont = 0; *_Pnext = (const_iterator *)(*_Pnext)->_Mynextiter; } } #endif /* _HAS_ITERATOR_DEBUGGING */ It's all over STL code, but it looks like locking happens only during 1) Debug Mode and 2) MultiTreaded application.

        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