C28112/3 的 InterlockedExchange 问题
InterlockedExchange issue with C28112/3
我遇到了几个代码分析问题:
(774): warning C28113: Accessing a local variable lAbort via an
Interlocked function: This is an unusual usage which could be
reconsidered.
(775): warning C28112: A variable (lAbort) which is accessed via an
Interlocked function must always be accessed via an Interlocked
function. See line 774: It is not always safe to access a variable
which is accessed via the Interlocked* family of functions in any
other way.
来自此代码:
BOOL CHttpDownloader::Abort()
{
volatile LONG lAbort = 0;
InterlockedExchange(&lAbort, m_lAbort);
return (lAbort != 0);
}
我承认这个代码/ class甚至不是我的。原作者暂时不支持,我自己也没用过这些类型的volatile
变量
然而,它一直有效,并不清楚修改代码以解决警告的正确方法。
类已被作者修改。该方法现在看起来像这样:
BOOL CHTTPDownloader::Abort()
{
return (m_lAbort != 0);
}
修改后的类:
我遇到了几个代码分析问题:
(774): warning C28113: Accessing a local variable lAbort via an Interlocked function: This is an unusual usage which could be reconsidered.
(775): warning C28112: A variable (lAbort) which is accessed via an Interlocked function must always be accessed via an Interlocked function. See line 774: It is not always safe to access a variable which is accessed via the Interlocked* family of functions in any other way.
来自此代码:
BOOL CHttpDownloader::Abort()
{
volatile LONG lAbort = 0;
InterlockedExchange(&lAbort, m_lAbort);
return (lAbort != 0);
}
我承认这个代码/ class甚至不是我的。原作者暂时不支持,我自己也没用过这些类型的volatile
变量
然而,它一直有效,并不清楚修改代码以解决警告的正确方法。
类已被作者修改。该方法现在看起来像这样:
BOOL CHTTPDownloader::Abort()
{
return (m_lAbort != 0);
}
修改后的类: