Thread: STL size thread safe

  1. #1
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683

    STL size thread safe

    Is the STL vector method size() thread safe.. most sites say it is but while I was debugging my program I found out that if more than one thread called this member a segmentation fault occured due to a static variable in the method...


    thanx in advance

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I'd very much doubt it is, why lose performance to make it thread safe when it's not needed in some (most?) cases.
    std::vector is a template, look at the implementation in the header file.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    No. Simple wrap the call to the STL object using any solution for thread synchronization.

    Kuphryn

  4. #4
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    Quote Originally Posted by kuphryn
    No. Simple wrap the call to the STL object using any solution for thread synchronization.

    Kuphryn
    anyway planing to write my own simple vector class.... The problem with using locks is it will surely brind down my programs performance since it accesses the vector and its members atleast 10 to 20 times a seccond..

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    I recommend that you wrap the STL vector.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to get the size of an STL container object?!!!
    By sam-j89 in forum C++ Programming
    Replies: 7
    Last Post: 05-12-2009, 02:56 PM
  2. Heapsort
    By xENGINEERx in forum C Programming
    Replies: 2
    Last Post: 03-30-2008, 07:17 PM
  3. are winsock functions thread safe?
    By *DEAD* in forum Networking/Device Communication
    Replies: 2
    Last Post: 12-15-2007, 10:37 AM
  4. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 11:27 AM
  5. C++ Threading?
    By draggy in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 12:16 PM