double MainWindow ProcRun int Tnum void threadFunction int myID int tN

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
double MainWindow::ProcRun(int Tnum)
{
//void threadFunction(int myID, int tNum);
for(int i=0; i<Tnum; i++)Tvector.push_back(std::thread(&MainWindow::threadFunction,this,i,Tnum));
std::this_thread::sleep_for(std::chrono::milliseconds(10));
StartCounter();
cv.notify_all();
for(auto &t: Tvector)
t.join();
double count = GetCounter();
Tvector.clear();
return count;
}
void MainWindow::threadFunction(int myID, int tNum)
{
std::unique_lock<std::mutex> locker(g_lock);
// std::cout<<"Waiting..."<<std::endl;
cv.wait(locker);
out_lock.lock();
// std::cout<<"Wake up! "<<myID<<std::endl;
out_lock.unlock();
for(unsigned int i=myID; i<fstmtx.size(); i+=tNum)
for(unsigned int j=0; j<fstmtx.size(); j++)
{
finalmtx[i][j]=0;
for(unsigned int k=0; k<fstmtx.size(); k++)
finalmtx[i][j] += fstmtx[i][k] * scndmtx[k][j];
}
}