This works fine as long as you’re happy to do the same task multiple times. I.e. the task is idempotent and cheap.
Why would both transactions see `used = 0`? The DB server tries to isolate transactions and actively hides effects of other transactions that have not committed yet.
https://www.postgresql.org/docs/current/transaction-iso.html...