如何在没有任务切换的情况下创建QThread

时间:2019-01-13 12:06:01

标签: c++ qt c++11 qt5 c++14

我正在开发Atmega328P MCU模拟器,但在计时器方面有一些问题。 Atmega328P中的计时器每62.5 ns(在16MHz上)滴答一次,我必须对此进行模拟。为了解决问题,我创建了此类

class DLL_EXPORT Timer : public QThread
...

void Timer::run()
{
    CCPU* cpu = dynamic_cast<CCPU*>(parent());
    if (cpu == nullptr)
    {
        exit();
        return;
    }

    QElapsedTimer timer_core;
    timer_core.start();
    while (1)
    {
        if (timer_core.nsecsElapsed() >= 62)
        {
            ++cpu->GetIOPorts()[0x26];
            timer_core.restart();
        }
    }
}

这似乎工作正常,但是关于CPU中的任务切换过程存在一些问题。如何为特定班级禁用该过程?

或者解决方案还有另一种方法?

0 个答案:

没有答案