使用:C++ (MinGW)
, Qt4.7.4
, Vista (操作系统)
, Intel Core2vPro
我需要以完全相同的方式处理两个巨大的文件。因此,我想从2个单独的线程中调用处理例程来处理这两个不同的文件。GUI线程不会执行任何重任务;只是显示一个标签并运行事件循环以检查线程终止条件的发出,并相应地退出主应用程序。我希望它会充分利用两个内核(Intel Core2),但恰恰相反,从任务管理器中可以看到一个内核被高度利用而另一个内核没有被利用(虽然并非每次运行代码时都是如此);而且处理这两个文件所需的时间要比处理一个文件的时间长得多(我原以为应该是相等或略多一些,但这几乎相当于在非线程应用程序中依次处理这两个文件)。我能否通过某种方式强制线程使用我指定的内核?
QThread* ptrThread1=new QThread;
QThread* ptrThread2=new QThread;
ProcessTimeConsuming* ptrPTC1=new ProcessTimeConsuming();
ProcessTimeConsuming* ptrPTC2=new ProcessTimeConsuming();
ptrPTC1->moveToThread(ptrThread1);
ptrPTC2->moveToThread(ptrThread2);
//make connections to specify what to do when processing ends, threads terminate etc
//display some label to give an idea that the code is in execution
ptrThread1->start();
ptrThread2->start(); //i want this thread to be executed in the core other than the one used above
ptrQApplication->exec(); //GUI event loop for label display and signal-slot monitoring