InterlockedExchange issue with C28112/3

378 views Asked by At

I am getting a couple of code analysis issues:

(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.

from this code:

BOOL CHttpDownloader::Abort()
{
  volatile LONG lAbort = 0;
  InterlockedExchange(&lAbort, m_lAbort);
  return (lAbort != 0);
}

I confess that this code / class is not even mine. The original author isn't supporting it right now, and I have not used these types of volatile variables myself.

However, it has always worked, and it is not clear on the right way to revise the code to address the warning.

1

There are 1 answers

0
Andrew Truckle On BEST ANSWER

The classes had been revised by the author. That method now looks like this:

BOOL CHTTPDownloader::Abort()
{
  return (m_lAbort != 0);
}

Here are the revised classes:

http://www.naughter.com/httpdownloaddlg.html