costOnVariable implementation in All-Interval Model.

Fix ThreadBarrier race condition with locks.