具有增强QT和mingw的多线程
Multithreading with boost QT and mingw
我正在QT上使用C++(librairie OpenCV)开发一个运行良好的GUI。现在我正在尝试使用boost对代码进行多线程处理我的方法是:
//creating thread group
thread_group mythread;
//then creating threads
mythread.create_thread(bind(&MainWindow::setbarvalue,this,0) ) ;
//set max and min of a progressbar to zero to get a floatting progressbar
mythread.create_thread(bind(&AVI2Image::Convert_AVItoImage,&avitoim,Nom,firstframe, lastframe,Nom_save,digitsnumber)) ;
AVI2Image:类
Convert_AVItoImage:功能
阿维托伊姆:类的实例
则属性
这条线也行。
问题从这一行开始:
mythread.create_thread(bind(&Lecture_containerYUV::container_YUV2yuv,&lectcont, Nom,Nom_save, width ,height,Redimonsionne,width_desir,height_desir, filter,inputsampling,
inputbitdepth,nbimages,digitsnumber,ry6,ru6,rv6,gy6,gu6,gv6,by6,bu6,bv6,coeff1,coeff2,coeff3,contrast,gamma,ry7,ru7,rv7,gy7,gu7,gv7,by7,bu7
,bv7,ry2,ru2,rv2,gy2,gu2,gv2,by2,bu2,bv2));
它的方法与上面相同,但这里我得到了这个错误:
C:UsersMidoDocumentsContainer_ConverterV_2.4mainwindow.cpp:363: erreur : no matching function for call to 'bind(void (Lecture_containerYUV::*)(std::string, std::string, int, int, bool, int, int, int, int, int, int, int, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double), Lecture_containerYUV*, std::string&, std::string&, int&, int&, bool&, int&, int&, int&, int&, int&, int&, int&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&, double&)'
和:
lectcont.container_YUV2yuv( Nom,Nom_save, width ,height,Redimonsionne,width_desir,height_desir, filter,inputsampling,
inputbitdepth,nbimages,digitsnumber,ry6,ru6,rv6,gy6,gu6,gv6,by6,bu6,bv6,coeff1,coeff2,coeff3,contrast,gamma,ry7,ru7,rv7,gy7,gu7,gv7,by7,bu7
,bv7,ry2,ru2,rv2,gy2,gu2,gv2,by2,bu2,bv2);
运行良好
明找不到函数,我不明白为什么!
有任何帮助请
我认为问题是您不能输入如此匹配的参数。我建议您使用C++11 的多线程
MyThread.h
#ifndef MyTHREAD_HPP
#define MyTHREAD_HPP
#include <thread>
#include <mutex>
class MyThread {
public:
MyThread();
void PrintOutMessage(string msg);
void PrintOut(int i, int j, int k);
void PrintOut(int i, int j);
~MyThread();
};
#endif
MyThread.cpp
#include "MyThread.hpp"
mutex _mu, _mu2;
MyThread::MyThread()
{
}
MyThread::~MyThread()
{
}
void MyThread::PrintOutMessage(string msg)
{
for (int l = 0; l < 10; l++)
{
lock(_mu, _mu2);
lock_guard<mutex>locker(_mu2, adopt_lock);
lock_guard<mutex>locker2(_mu, adopt_lock);
cout<< "message:" << msg << endl;
Sleep(200);
}
}
void MyThread::PrintOut(int i,int j,int k)
{
for (int l = 0; l < 10; l++)
{
lock(_mu, _mu2);
//lock_guard<mutex>locker(_mu2, adopt_lock);
//lock_guard<mutex>locker2(_mu, adopt_lock);
unique_lock<mutex>locker(_mu2, adopt_lock);
unique_lock<mutex>locker2(_mu, adopt_lock);
cout << "message:" << i << ", " << j << ", " << k << endl;
Sleep(200);
}
}
void MyThread::PrintOut(int i, int j)
{
for (int l = 0; l < 10; l++)
{
lock(_mu, _mu2);
lock_guard<mutex>locker(_mu2, adopt_lock);
lock_guard<mutex>locker2(_mu, adopt_lock);
cout << "message:" << i << ", " << j << endl;
Sleep(200);
}
}
main.cpp
#include "MyThread.hpp"
void (MyThread::*memfunc)(int,int) = &MyThread::PrintOut;
void (MyThread::*memfunc2)(int, int,int) = &MyThread::PrintOut;
void PrintOutmainfunc(int i, int j, int k)
{
for (int l = 0; l < 10; l++)
{
cout << "message:" << i << ", " << j << ", " << k << endl;
Sleep(200);
}
}
int main (){
string msg = " hello world";
int i = 10, j = 20, k = 30;
// string str = lexical_cast<string>(i);
//cout << "str: " << str << endl;
MyThread mythread;
thread t1(memfunc, mythread, i, j);
thread t2(memfunc2, mythread, i, j, k);
thread t3(&MyThread::PrintOutMessage, mythread, msg);
//thread t4(PrintOutmainfunc, i, j, k);
//thread t3(bind(&MyThread::PrintOutMessage, mythread, msg));
t1.join();
t2.join();
t3.join();
//t4.join();
system("PAUSE");
return 0;
}
在这个例子中,我为多线程提供了所有可能的选项
相关文章:
- 在C++中使用cURL和多线程
- 多线程双缓冲区
- 为什么我的多线程作业队列崩溃
- 在main()之外初始化std::vector会导致性能下降(多线程)
- 试图创建一个多线程程序来查找0-100000000之间的总素数
- 为什么一个向量上的多线程操作很慢
- 学习多线程C++:添加线程不会使执行速度更快,即使它看起来应该
- 全局变量 多读取器 一个写入器多线程安全?
- boost::文件系统::recursive_directory_iterator多线程安全
- 如何阻止TensorFlow的多线程
- 如何在多线程中正确使用unique_ptr进行多态性?
- 并发/多线程:是否可以以这种方式生成相同的输出?
- sigwait() 在多线程程序中不起作用
- 多线程程序中出现意外的内存泄漏
- 静态 constexpr 类成员变量对多线程读取是否安全?
- 多线程比没有线程C++慢
- 具有 C++11 多线程的特征库
- 通过安装信号处理程序关闭多线程应用程序
- 成员变量在多线程 C++ 时自行更改
- 具有增强QT和mingw的多线程