QtQtConcurrent 使用方式

说明:QtConcurrent 的线程函数启动方式略述。

1) 全局函数或静态函 ,作为线程函数

1 void threadFunc()
2 {
3     //...add 
4 }
5 QtConcurrent::run(threadFunc);

2) 类成员函数作为线程函数

       

 1 class worker
 2 {
 3    public:
 5        Worker();
 7        ~Worker();
 9        void threadFunc();
10        void start(); 
11 };
13 void worker::threadFunc()
14 {
15    //... add
16 }
18 void worker::start()
19 {
20      QtConcurrent::run(this,&worker::threadFunc);
21 }

3) 结构体函数作为线程函数


 1 sturct worker
 2  {
 3      int ID;
 4      void worker::threadFunc()
 5      {
 6        //... add
 7      }
 8  };//end    
 9 
10 worker  work;
11 QtConcurrent::run(&work,&worker::threadFunc);


 

补充:QtConcurrent默认使用全局线程池,经实测(CPU:i3-4150)双核四线程处理器,

开启的最大线程数即为4;

原文地址:https://www.cnblogs.com/Esperanto/p/8668627.html