Fix invalid threadId reference when threadId not initialized.