Devel Lib
CMutexVector< T > Class Reference

A class for thread-safe handling of vectors. More...

#include <MutexVector.h>

Detailed Description

A class for thread-safe handling of vectors.

This class encapsulates a std::vector<T>, providing an interface for thread-safe operations on the vector.

Example

This class must be used when you want to manipulate a vector in a multi-threaded context. Here is a simple usage example:

#include "CMutexVector.h"
#include <thread>
void addToVec(int value) {
mutexVec.push_back(value);
}
int main() {
// Launch two threads that both add to the vector
std::thread t1(addToVec, 1);
std::thread t2(addToVec, 2);
// Wait for both threads to finish
t1.join();
t2.join();
// Print the final size of the vector
std::cout << "Final vector size: " << mutexVec.size() << std::endl;
return 0;
}
Definition: MutexVector.h:65
void push_back(const T &i_oValue)
Appends a new element to the end of the vector.
Definition: MutexVector.h:374
size_t size() const
Returns the size of the vector.
Definition: MutexVector.h:308

The documentation for this class was generated from the following file: