Quote:
Originally Posted by wireties
True but these class members are native machine word-sized thus changing them is an atomic operation in this context. It may not be desirable but it won't screw up.
|
I think you're correct that there is no danger of segmentation faults. However, if access to the variables is not synchronized then the potential for logic errors exist.
Example, in the following code the first if-statement could execute with the values of min/max input set to one set of values. The thread executing this code could then be preempted (depending on the thread priority and scheduling algorithm being used) by the application thread and the values of min/max input changed. The original thread would then continue executing the code with new values of min/max input causing undesireable results.
Code:
if (fabs(m_error) > (m_maximumInput - m_minimumInput) / 2)
{
if (m_error > 0)
{
m_error = m_error - m_maximumInput + m_minimumInput;
}
else
{
m_error = m_error + m_maximumInput - m_minimumInput;
}
}