Need synchronization for an increment-only counter?

If you just used an int or long variable then you would need synchronization – incrementing involves read / increment-locally / write, which is far from an atomic operation. (Even if the variable is volatile to avoid memory model concerns of staleness, you’d still have three distinct operations, with the possibility of being pre-empted between … Read more

How do I increment or decrement a number in Common Lisp?

Use the built-in “+” or “-” functions, or their shorthand “1+” or “1-“, if you just want to use the result, without modifying the original number (the argument). If you do want to modify the original place (containing a number), then use the built-in “incf” or “decf” functions. Using the addition operator: (setf num 41) … Read more