Hmm ... only if it's already set inVacuum true ... there's a window where it has not.
I wonder whether we could change CIC so that the "reference snapshot" lists only transactions that are running and have already determined their serializable snapshot (ie, have set proc->xmin). Xacts that haven't yet done that can be ignored because they couldn't possibly see the dead tuples we're worried about, no?
Yes, it may work. Do we need to take some extra care because proc-xmin is set while holding SHARED lock on proc array ?
Then we could rearrange the order of operations in vacuum_rel so that we lock the target rel before we acquire a snapshot. Then a vacuum waiting for the CIC cannot cause a deadlock.