Преглед на файлове

don't wait for termination if we are already done

Cédric Augonnet преди 16 години
родител
ревизия
47ec8bb2c8
променени са 1 файла, в които са добавени 5 реда и са изтрити 1 реда
  1. 5 1
      tests/microbenchs/async-tasks-overhead.c

+ 5 - 1
tests/microbenchs/async-tasks-overhead.c

@@ -27,6 +27,8 @@ static pthread_cond_t cond;
 static unsigned ntasks = 65536;
 static unsigned cnt;
 
+static unsigned finished = 0;
+
 static void *dummy_func(void *arg __attribute__ ((unused)))
 {
 	return NULL;
@@ -48,6 +50,7 @@ void callback(void *arg)
 	if (res == 0)
 	{
 		pthread_mutex_lock(&mutex);
+		finished = 1;
 		pthread_cond_signal(&cond);
 		pthread_mutex_unlock(&mutex);
 	}
@@ -103,7 +106,8 @@ int main(int argc, char **argv)
 	}
 
 	pthread_mutex_lock(&mutex);
-	pthread_cond_wait(&cond, &mutex);
+	if (!finished)
+		pthread_cond_wait(&cond, &mutex);
 	pthread_mutex_unlock(&mutex);
 
 	gettimeofday(&end, NULL);