Detecting access anomalies in programs with critical sections