Thursday 13 February 2014

Thread Safety - Don't #1

Do not oscillate the value of an integer as the back-bone of making your code thread safe...

IT IS NOT SAFE
IT IS NOT RIGHT
IT IS NOT CLEVER....


int m_Count = 0;


do
{
    if ( m_Count++ == 0)
    {
        DoFunction1();
    }
    else
    {
        DoFunction2();
        m_Count = 0;
    }
}
while ( true );

This is not good code... This is bad... Evil... Malign... Code.

No comments:

Post a Comment