Skip to content
Snippets Groups Projects
Commit c3ce403d authored by Martin Larralde's avatar Martin Larralde
Browse files

Add an `atomic_vector` wrapper for `vector` where `push_back` is thread-safe

parent 8558fda7
No related branches found
No related tags found
No related merge requests found
#ifndef _SAFEVEC_HPP
#define _SAFEVEC_HPP
#include <mutex>
#include <vector>
template <class T>
class atomic_vector: public std::vector<T> {
protected:
std::mutex mutex;
public:
atomic_vector(): std::vector<T>(), mutex() {}
void push_back(const T& val) {
mutex.lock();
std::vector<T>::push_back(val);
mutex.unlock();
}
};
#endif
from libcpp.vector cimport vector
cdef extern from "_atomic_vector.hpp" nogil:
cdef cppclass atomic_vector[T](vector[T]):
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment