Availability:built-in
 flag(+Key, -Old, 
+New)True when Old is the current value of the flag Key 
and the flag has been set to New. New can be an 
arithmetic expression. The update is atomic. This predicate can 
be used to create a shared global counter as illustrated in the 
example below.
flag(+Key, -Old, 
+New)True when Old is the current value of the flag Key 
and the flag has been set to New. New can be an 
arithmetic expression. The update is atomic. This predicate can 
be used to create a shared global counter as illustrated in the 
example below.
next_id(Id) :-
    flag(my_id, Id, Id+1).