getAndIncrement
GetAndIncrement is an atomic operation commonly provided by concurrent programming libraries. It returns the current value of an atomic numeric object and then increments that value by one, all as a single indivisible step. This atomicity ensures that no interleaving thread observes a partial update and that the increment is immediately visible to all threads.
In practice, getAndIncrement is used when the previous value is needed and the sequence must advance safely
Semantics and behavior: the operation is thread-safe and lock-free in typical implementations, relying on low-level primitives
Common uses include counting in multithreaded scenarios, generating unique sequence numbers, and implementing thread-safe indices or