使用公共循环缓冲区启动两个线程

时间:2018-12-05 11:50:53

标签: qt buffer mutex qthread

我有两个职能。一个在搜索类中,被命名为producer1,第二个在search2类中,被命名为Consumer1。当这两个函数是独立的时,我使用这些命令,并且两个函数同时作为线程工作。

 thread1 = new QThread();
 thread2 = new QThread();
 mySearch = new Search() ;
 mySearch2 = new Search2() ;

 mySearch->connect(mySearch,SIGNAL(transmit_to_gui(QStringList)),this,SLOT(receive_from_object(QStringList)));
 mySearch2->connect(mySearch2,SIGNAL(transmit_to_gui1(QStringList)),this,SLOT(receive_from_object1(QStringList)));      

  connect(mySearch, SIGNAL(workRequested()), thread1, SLOT(start()));
  connect(thread1, SIGNAL(started()), mySearch, SLOT(producer1()));
  connect(mySearch, SIGNAL(finished()), thread1, SLOT(quit()), Qt::DirectConnection);
  thread1->start();

 connect(mySearch2, SIGNAL(workRequested2()), thread2, SLOT(start()));
 connect(thread2, SIGNAL(started()), mySearch2, SLOT(consumer1()));
 connect(mySearch2, SIGNAL(finished2()), thread2, SLOT(quit()), Qt::DirectConnection);
thread2->start();

但是,当它们具有公共的循环缓冲区并且相互依赖时,上述命令不会激活线程。有人可以帮忙吗?

先谢谢了。

0 个答案:

没有答案