Move statement to appease Coverity

Coverity thinks we have a use-before-assigned of r2 here, despite the
join(), so let's just move the test inside the thread to make this
warning go away.

Signed-off-by: Nadav Har'El <nyh@cloudius-systems.com>