C++ 使用设置关联掩码从QueryPerformanceCounter中的同一核心获取时间

C++ 使用设置关联掩码从QueryPerformanceCounter中的同一核心获取时间,c++,windows,mingw,performancecounter,setthreadaffinitymask,C++,Windows,Mingw,Performancecounter,Setthreadaffinitymask,我使用的是以微秒为单位的QueryPerformance计数器。我写StartCounter()函数初始化计时器,写GetCounter()函数以微秒为单位获取时间。My GetCounter()函数由不同的线程使用。我想确定我从同一个核心得到了时间。我编写此代码的目的是: #include <iostream> #include <pthread.h> #include <semaphore.h> using namespace std; double P

我使用的是以微秒为单位的QueryPerformance计数器。我写StartCounter()函数初始化计时器,写GetCounter()函数以微秒为单位获取时间。My GetCounter()函数由不同的线程使用。我想确定我从同一个核心得到了时间。我编写此代码的目的是:

#include <iostream>
#include <pthread.h>
#include <semaphore.h>
using namespace std;

double PCFreq = 0.0;
__int64 CounterStart = 0;

void StartCounter()
{
    cpu_set_t mask1;
    CPU_ZERO(&mask1);
    CPU_SET(1,&mask1);
    pthread_setaffinity_np(pthread_self(),sizeof(mask1),&mask1);

    LARGE_INTEGER li;
    if(!QueryPerformanceFrequency(&li))
    cout << "QueryPerformanceFrequency failed!\n";

    PCFreq = double(li.QuadPart)/1000000.0;

    QueryPerformanceCounter(&li);
    CounterStart = li.QuadPart;
}

double GetCounter(){
    LARGE_INTEGER li;
    QueryPerformanceCounter(&li);
    return double(li.QuadPart-CounterStart)/PCFreq;
}
#包括
#包括
#包括
使用名称空间std;
双PCFreq=0.0;
__int64 countstart=0;
void StartCounter()
{
cpu设置mask1;
CPU_零(&mask1);
CPU_组(1和mask1);
pthread_setaffinity_np(pthread_self(),sizeof(mask1),&mask1);
大整数李;
if(!QueryPerformanceFrequency(&li))

难道我猜他们应该在同一个线程中运行,这样才有意义吗。