SELECT FOR UPDATE locks the selected rows until the transaction ends. Another writer targeting a locked row usually waits. Ordinary readers can still read a committed row version, so a row lock isn't a table-wide read freeze. Keep the transaction short and avoid user interaction while holding locks.
NOWAIT reports a conflict immediately. SKIP LOCKED skips rows another transaction has locked, which suits competing queue workers that may process different jobs. It doesn't provide a complete consistent report because it intentionally omits unavailable rows.
The first exercise uses a labeled two-session model because PGlite supplies one connection. The SQL exercises execute real locking syntax in that connection, but no competing worker exists there. A correct queue design also needs a durable claim state, retries after worker failure and a transaction that contains both selection and claim.
B waits for A to release its row lock before completing the update.