Browse Source

If have_longpoll is enabled, then make it mandatory the longpoll thread is killed from the outside, avoiding the race of trying to kill off a longpoll
thread that has potentially exited already.

Con Kolivas 14 years ago
parent
commit
8c066c4257
1 changed files with 7 additions and 2 deletions
  1. 7 2
      main.c

+ 7 - 2
main.c

@@ -4972,11 +4972,15 @@ static void *longpoll_thread(void *userdata)
 	}
 
 out:
-	have_longpoll = false;
-	tq_freeze(mythr->q);
 	if (curl)
 		curl_easy_cleanup(curl);
 
+	/* Wait indefinitely if longpoll is flagged as existing, thus making
+	 * this thread only die if killed from elsewhere, usually in
+	 * thr_info_cancel */
+	if (have_longpoll)
+		tq_pop(mythr->q, NULL);
+	tq_freeze(mythr->q);
 	return NULL;
 }
 
@@ -4986,6 +4990,7 @@ static void stop_longpoll(void)
 
 	thr_info_cancel(thr);
 	have_longpoll = false;
+	tq_freeze(thr->q);
 }
 
 static void start_longpoll(void)