There is one mistake
Error 3 error C2280: 'std::mutex::mutex(const std::mutex &)' : attempting to reference a deleted function
It must be repaired. How does it come about? There is one class that implements a queue. In the end. I read the documentation that mutex cannot be copied. Good. I pass to the function a link to this object. But unfortunately I catch this error.
main() function
int main() { Queue<MyStruct> tasks; //создаем объект std::thread t1(buildQueue, tasks); //кидаем ссылку return 0; } void buildQueue(Queue<MyStruct> &taskQueue) { ; //ничего не делает. } Class queue
template <typename T> class Queue{ private: const unsigned int MAX = 5; std::deque<T> newQueue; std::mutex d_mutex; std::condition_variable d_condition; public: void push(T const& value) { { std::unique_lock<std::mutex> lock(this->d_mutex); newQueue.push_front(value); } this->d_condition.notify_one(); } T pop() { std::unique_lock<std::mutex> lock(this->d_mutex); this->d_condition.wait(lock, [=]{ return !this->newQueue.empty(); }); T rc(std::move(this->newQueue.back())); this->newQueue.pop_back(); return rc; } }; I read somewhere that such a problem arises in the case of a constructor that is trying to copy mutex. Although I do not seem to copy anything.
MyStruct? It is important. And yet, give the line in which the error. - VladDstruct MyStruct { int test; };There the data will be placed, and the structure itself will fall into the list. - Ascelhem