bugfix: increment and compare in atomic call.