Due to the nature of multithreading, using a "ready check" mechanism may 
introduce a deadlock. For example:

Suppose all tasks have been submitted to the executor, and the last thread 
checks the entire list and finds
no ready tasks. It then goes to sleep, waiting for a new task. However, for 
some multithreading-related reason,
a task becomes ready after the check. Since no other thread is aware of this 
and no new tasks are being added to
the executor, a deadlock occurs.

In VVC, this function is unnecessary because we use a scoreboard. All tasks 
submitted to the executor are ready tasks.
---
 libavcodec/executor.c   | 6 ++----
 libavcodec/executor.h   | 3 ---
 libavcodec/vvc/thread.c | 8 --------
 3 files changed, 2 insertions(+), 15 deletions(-)

diff --git a/libavcodec/executor.c b/libavcodec/executor.c
index 574c5c7be7..21ebad3def 100644
--- a/libavcodec/executor.c
+++ b/libavcodec/executor.c
@@ -79,10 +79,8 @@ static void add_task(FFTask **prev, FFTask *t)
 static int run_one_task(FFExecutor *e, void *lc)
 {
     FFTaskCallbacks *cb = &e->cb;
-    FFTask **prev;
+    FFTask **prev = &e->tasks;
 
-    for (prev = &e->tasks; *prev && !cb->ready(*prev, cb->user_data); prev = 
&(*prev)->next)
-        /* nothing */;
     if (*prev) {
         FFTask *t = remove_task(prev, *prev);
         if (e->thread_count > 0)
@@ -143,7 +141,7 @@ FFExecutor* ff_executor_alloc(const FFTaskCallbacks *cb, 
int thread_count)
 {
     FFExecutor *e;
     int has_lock = 0, has_cond = 0;
-    if (!cb || !cb->user_data || !cb->ready || !cb->run || 
!cb->priority_higher)
+    if (!cb || !cb->user_data || !cb->run || !cb->priority_higher)
         return NULL;
 
     e = av_mallocz(sizeof(*e));
diff --git a/libavcodec/executor.h b/libavcodec/executor.h
index 2d02734ad6..51763ec25e 100644
--- a/libavcodec/executor.h
+++ b/libavcodec/executor.h
@@ -42,9 +42,6 @@ typedef struct FFTaskCallbacks {
     // return 1 if a's priority > b's priority
     int (*priority_higher)(const FFTask *a, const FFTask *b);
 
-    // task is ready for run
-    int (*ready)(const FFTask *t, void *user_data);
-
     // run the task
     int (*run)(FFTask *t, void *local_context, void *user_data);
 } FFTaskCallbacks;
diff --git a/libavcodec/vvc/thread.c b/libavcodec/vvc/thread.c
index e6907fd764..a8c19b17cf 100644
--- a/libavcodec/vvc/thread.c
+++ b/libavcodec/vvc/thread.c
@@ -372,13 +372,6 @@ static int task_is_stage_ready(VVCTask *t, int add)
     return task_has_target_score(t, stage, score);
 }
 
-static int task_ready(const FFTask *_t, void *user_data)
-{
-    VVCTask *t = (VVCTask*)_t;
-
-    return task_is_stage_ready(t, 0);
-}
-
 #define CHECK(a, b)                         \
     do {                                    \
         if ((a) != (b))                     \
@@ -689,7 +682,6 @@ FFExecutor* ff_vvc_executor_alloc(VVCContext *s, const int 
thread_count)
         s,
         sizeof(VVCLocalContext),
         task_priority_higher,
-        task_ready,
         task_run,
     };
     return ff_executor_alloc(&callbacks, thread_count);
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to