Fix for possible race condition, happened for Scott W. with space (-Os) optimization. Need to use a memory barrier (see  http://mcuoneclipse.com/2014/01/26/entercritical-and-exitcritical-why-things-are-failing-badly/#comment-18650)