I have an application that continuously std::vector::push_back elements into a vector. As it is a real-time system I cannot afford it to stall at any time. Unfortunately, when the reserved memory is exhausted the push_back automatic memory allocation does cause stalls (up to 800ms in my measurements).
I have tackled the problem by having a second thread that monitors when the available memory and calls a std::vector::reserve if necessary.
My question is: is it safe to execute reserve and push_back concurrently?
(clearly under the assumption that the push_back will not reallocate memory)
Thanks!