I would like to push elements into a queue using vector of threads, but am getting an error: no matching constructor for initialization of thread. Can you please help me to fix it.
#include <thread>
#include <queue>
using namespace std;
void thread_spawn_q(queue<int> &q)
{
vector<thread> ths;
for (int i = 1; i <= 1000; i++)
{
ths.push_back(thread(&queue<int>::push, &q, i));
}
for (auto &th : ths)
{
th.join();
}
}
int main()
{
queue<int> q = queue<int>();
thread_spawn_q(q);
return 0;
}