Skip to content

periphery_task定时器为空时,调用Stop可能时,可能存在定时器数组为空但访问top函数导致内存访问异常 #229

Description

@yujun411522

    // 这里需要判断队列不是empty,否则下面执行top会出现内存访问异常。这里解释下为何会有这种场景:
    // 此时m_timerTasks为空,且m_exited为false也就是还没stop,
    // 此时定时器线程执行到if(m_exited.load(std::memory_order_relaxed)){break;}时 为false,
    // 所以会往下走执行if(!pred()) {continue;}。
    // 此时恰好调用了Timer::Stop,也就是设置了m_exited为true,所以pred()条件为true
    // 自然就会走到下面m_timerTasks.top()等逻辑,就会出现内存访问异常。

    if (m_timerTasks.empty()) {
        continue;
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions