Deadlock fix: lock outputs in a later phase
Deadlock fix: lock outputs in a later phase

We were locking the outputs of an instantiated rule before making its
dependencies up to date. We are now locking them after.

The idea behind locking them early was to be able to abort early when another
thread has already produced the same target (the target needs to be locked to
detect this).

However, a target A and its dependency B can have the same side output O. The
thread T_B producing B would then attempt to lock O while T_A still has it
under lock and is waiting for T_B to complete: a deadlock.

The solution is for T_A to not acquire the lock until after T_B is done. This
means that we also have postpone aborting. Performance implications unclear.
Thus, we need to postpone until after producing the dependencies.

texttheater/produce,texttheater/produce