File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed
Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,9 @@ void WorkerThreadPool::_process_task(Task *p_task) {
7272 p_task->pool_thread_index = pool_thread_index;
7373 prev_task = curr_thread.current_task ;
7474 curr_thread.current_task = p_task;
75+ if (p_task->pending_notify_yield_over ) {
76+ curr_thread.yield_is_over = true ;
77+ }
7578 task_mutex.unlock ();
7679 }
7780#endif
@@ -491,7 +494,11 @@ void WorkerThreadPool::notify_yield_over(TaskID p_task_id) {
491494 ERR_FAIL_MSG (" Invalid Task ID." );
492495 }
493496 Task *task = *taskp;
494- if (task->completed ) {
497+ if (task->pool_thread_index == -1 ) { // Completed or not started yet.
498+ if (!task->completed ) {
499+ // This avoids a race condition where a task is created and yield-over called before it's processed.
500+ task->pending_notify_yield_over = true ;
501+ }
495502 task_mutex.unlock ();
496503 return ;
497504 }
Original file line number Diff line number Diff line change @@ -81,7 +81,8 @@ class WorkerThreadPool : public Object {
8181 void *native_func_userdata = nullptr ;
8282 String description;
8383 Semaphore done_semaphore; // For user threads awaiting.
84- bool completed = false ;
84+ bool completed : 1 ;
85+ bool pending_notify_yield_over : 1 ;
8586 Group *group = nullptr ;
8687 SelfList<Task> task_elem;
8788 uint32_t waiting_pool = 0 ;
@@ -92,6 +93,8 @@ class WorkerThreadPool : public Object {
9293
9394 void free_template_userdata ();
9495 Task () :
96+ completed (false ),
97+ pending_notify_yield_over (false ),
9598 task_elem (this ) {}
9699 };
97100
You can’t perform that action at this time.
0 commit comments