首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C线程中的自我增量是安全的吗?

C线程中的自我增量是安全的吗?
EN

Stack Overflow用户
提问于 2013-03-20 09:20:49
回答 3查看 2.1K关注 0票数 15

我在FreeRTOS (FreeRTOSV7.4.0\FreeRTOS\Source\tasks.c)中找到了一些代码:

代码语言:javascript
运行
复制
void vTaskSuspendAll( void )
{
    /* A critical section is not required as the variable is of type
    portBASE_TYPE. */
    ++uxSchedulerSuspended;
}

明确表示不需要保护,因为类型是"portBASE_TYPE",是"long“类型。我的理解是,它假定此类型的自我增量是原子的。但在我反汇编后,我找不到任何证据,这是一个简单的加载->添加->存储。那这是个问题吗?

代码语言:javascript
运行
复制
void vTaskSuspendAll( void )
{
        /* A critical section is not required as the variable is of type
        portBASE_TYPE. */
        ++uxSchedulerSuspended;
 4dc:   4b03            ldr     r3, [pc, #12]   ; (4ec <vTaskSuspendAll+0x10>)
 4de:   f8d3 2118       ldr.w   r2, [r3, #280]  ; 0x118
 4e2:   1c50            adds    r0, r2, #1
 4e4:   f8c3 0118       str.w   r0, [r3, #280]  ; 0x118
 4e8:   4770            bx      lr
 4ea:   bf00            nop
 4ec:   00000000        .word   0x00000000

000004f0 <xTaskGetTickCount>:
        return xAlreadyYielded;
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15513622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档