cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.87k stars 1.69k forks source link

Passing a concurrent queue object over reference through a function is not working #260

Closed bharathraja closed 3 years ago

bharathraja commented 3 years ago

The data type with which the concurrent queue is initialised is a struct of multiple datatypes. The dequeue is in a separate function running in a separate thread. when the function is called through the thread and the reference is passed through std::ref, it is giving error.

sample code: ` struct frame_data{ Mat frame; int frame_num; };

void mask (moodycamel::BlockingConcurrentQueue<frame_data*>& capture){ frame_data item; capture->wait_dequeue(item); }

main(){ moodycamel::BlockingConcurrentQueue capture;

std::thread(mask, std::ref(capture)).detach(); }`

bharathraja commented 3 years ago

I just passed by simple address reference(&) instead of using std::ref, it is working good. I was converting the code to replace zmq with the concurrent queues, was without thinking used the same syntax.