If the CaS fails you need to retry the operation.
int value; do value = shared_var; while( ! cas( &shared_var, value, value+1 ) )