Can C++ std::vector handle push_back from multithreads at the same time?

OhMyGosh

I have multithreads program that each thread will return a string and then it will store in a shared vector container. I wonder is it possible for a std::vector to handle this case or I have to use locks to protect it?

Yakk - Adam Nevraumont

No. Barring a handful of methods, only const methods are concurrency safe.

(those exceptions are iterator getting/index access methods)

If any thread does such non-const access, no other thread may do any access at all.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can C++ std::vector handle push_back from multithreads at the same time?

From Java

Is it safe to push_back an element from the same vector?

From Java

Insert or push_back to end of a std::vector?

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

vector::push_back and std::move

From Dev

Implementatnion of std::vector::push_back in MSVC

From Dev

std::vector's push_back() causing a strange compile-time error message

From Dev

C++ how to push_back an array int[10] to std::vector<int[10]>?

From Dev

C++ reference changes when push_back new element to std::vector

From Dev

C++ STD Vector push_back doesn't seem to work

From Dev

C++ how to push_back an array int[10] to std::vector<int[10]>?

From Dev

c++ push_back() a struct into a vector

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

Calling std::vector::push_back() is changing previous elements in vector?

From Dev

no matching function for call to std::vector<std::tuple> push_back

From Dev

Taking the argument by && in std::vector push_back() and std::map operator[]

From Dev

Thread safety std::vector push_back and reserve

From Dev

Cost of std::vector::push_back either succeeding or having no effect?

From Dev

Why std::vector::push_back needs the assignment operator

From Dev

Weird segment fault in function push_back of std::vector

From Dev

std::vector segmentation fault during push_back

From Dev

Thread safety std::vector push_back and reserve

From Dev

std::vector of OpenCV points, no push_back method

From Dev

Why std::vector::push_back segfaults with virtual destructor?

From Dev

Examples where std::vector::emplace_back is slower than std::vector::push_back?

From Dev

C++ Vector: push_back Objects vs push_back Pointers performance

From Dev

c++ vector - what's the difference between push_back(*new obj()) and push_back(obj())?

From Dev

Can't push_back a class into an object vector inside a for loop

From Dev

Why can't I push_back to a vector of const elements?

Related Related

  1. 1

    Can C++ std::vector handle push_back from multithreads at the same time?

  2. 2

    Is it safe to push_back an element from the same vector?

  3. 3

    Insert or push_back to end of a std::vector?

  4. 4

    Implementatnion of std::vector::push_back in MSVC

  5. 5

    vector::push_back and std::move

  6. 6

    Implementatnion of std::vector::push_back in MSVC

  7. 7

    std::vector's push_back() causing a strange compile-time error message

  8. 8

    C++ how to push_back an array int[10] to std::vector<int[10]>?

  9. 9

    C++ reference changes when push_back new element to std::vector

  10. 10

    C++ STD Vector push_back doesn't seem to work

  11. 11

    C++ how to push_back an array int[10] to std::vector<int[10]>?

  12. 12

    c++ push_back() a struct into a vector

  13. 13

    Calling std::vector::push_back() is changing previous elements in vector?

  14. 14

    Calling std::vector::push_back() is changing previous elements in vector?

  15. 15

    no matching function for call to std::vector<std::tuple> push_back

  16. 16

    Taking the argument by && in std::vector push_back() and std::map operator[]

  17. 17

    Thread safety std::vector push_back and reserve

  18. 18

    Cost of std::vector::push_back either succeeding or having no effect?

  19. 19

    Why std::vector::push_back needs the assignment operator

  20. 20

    Weird segment fault in function push_back of std::vector

  21. 21

    std::vector segmentation fault during push_back

  22. 22

    Thread safety std::vector push_back and reserve

  23. 23

    std::vector of OpenCV points, no push_back method

  24. 24

    Why std::vector::push_back segfaults with virtual destructor?

  25. 25

    Examples where std::vector::emplace_back is slower than std::vector::push_back?

  26. 26

    C++ Vector: push_back Objects vs push_back Pointers performance

  27. 27

    c++ vector - what's the difference between push_back(*new obj()) and push_back(obj())?

  28. 28

    Can't push_back a class into an object vector inside a for loop

  29. 29

    Why can't I push_back to a vector of const elements?

HotTag

Archive