Przeglądaj źródła

Bug fix: when starpu_wait_task is called on a task, we block until both the
codelet's function and its callback have been executed (so that we don't
destroy the task while it's still in use within the driver for instance). On
the other hand, we need to specify that a task have been executed before its
callback is executed so that it is possible to express dependencies within the
callback.
As a consequence, the j->terminated flag may now have 3 different values:
- 0: the task was not executed at all
- 1: only the codelet function was executed
- 2: both the function and the callback have been executed (we may call
starpu_task_destroy)

Cédric Augonnet 15 lat temu
rodzic
commit
24ac275612
1 zmienionych plików z 11 dodań i 2 usunięć
  1. 11 2
      src/core/jobs.c

+ 11 - 2
src/core/jobs.c

@@ -81,7 +81,12 @@ void _starpu_wait_job(starpu_job_t j)
 
 	PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 
-	while (!j->terminated)
+	/* We wait for the flag to have a value of 2 which means that both the
+	 * codelet's implementation and its callback have been executed. That
+	 * way, _starpu_wait_job won't return until the entire task was really
+	 * executed (so that we cannot destroy the task while it is still being
+	 * manipulated by the driver). */
+	while (j->terminated != 2)
 		PTHREAD_COND_WAIT(&j->sync_cond, &j->sync_mutex);
 
 	PTHREAD_MUTEX_UNLOCK(&j->sync_mutex);
@@ -97,7 +102,8 @@ void _starpu_handle_job_termination(starpu_job_t j)
 
 	/* We must have set the j->terminated flag early, so that it is
 	 * possible to express task dependencies within the callback
-	 * function. */
+	 * function. A value of 1 means that the codelet was executed but that
+	 * the callback is not done yet. */
 	PTHREAD_MUTEX_LOCK(&j->sync_mutex);
 	j->terminated = 1;
 	PTHREAD_MUTEX_UNLOCK(&j->sync_mutex);
@@ -133,6 +139,9 @@ void _starpu_handle_job_termination(starpu_job_t j)
 		/* we do not desallocate the job structure if some is going to
 		 * wait after the task */
 		PTHREAD_MUTEX_LOCK(&j->sync_mutex);
+		/* A value of 2 is put to specify that not only the codelet but
+		 * also the callback were executed. */
+		j->terminated = 2;
 		PTHREAD_COND_BROADCAST(&j->sync_cond);
 		PTHREAD_MUTEX_UNLOCK(&j->sync_mutex);
 	}