Fixed print mutex locks/unlocks to avoid printing race conditions.