【发布时间】:2017-06-23 06:13:06
【问题描述】:
在获得结果并将 Post_Bits 清除为其原始状态 Post_Bits &= (~Post); 并测试条件之前禁用中断有什么意义,如果之前看到特定的 Post res = Post_Bits & Post;。
例如,如果Post_Bits 用于另一个函数并且您在此处更改它,是否在禁用/启用中断中清除它会使其线程安全?
BOOL Post_a_Note(Post_t Post) // Post_t is a 32bit number
{
Post_t res; //Final Result
UINT16 capture = INTDisableInterrupts();
res = Post_Bits & Post;
Post_Bits &= (~Post);
INTRestoreInterrupts(capture);
return (res != 0);
}
【问题讨论】:
-
因为如果在第 5 行和第 6 行之间发生中断,并设置您正在检查的位,您将清除该位但将其报告为未设置:因此缺少该事件。
-
中断不是线程,线程安全是另一头野兽。
标签: c thread-safety interrupt