@@ -132,15 +132,18 @@ namespace detail {
132132
133133 if (syncing_on_id == NOT_SYNCING && jobs.size () < MAX_CONCURRENT_JOBS && !command_queue.empty ()) {
134134 const auto info = command_queue.front ();
135- command_queue.pop ();
136135 if (info.pkg .cmd == command_type::SHUTDOWN) {
137- assert (command_queue.empty () );
136+ assert (command_queue.size () == 1 );
138137 done = true ;
139138 } else if (info.pkg .cmd == command_type::SYNC) {
140139 syncing_on_id = std::get<sync_data>(info.pkg .data ).sync_id ;
141140 } else {
142- handle_command (info.pkg , info.dependencies );
141+ if (!handle_command (info.pkg , info.dependencies )) {
142+ // In case the command couldn't be handled, don't pop it from the queue.
143+ continue ;
144+ }
143145 }
146+ command_queue.pop ();
144147 }
145148
146149 if (first_command_received) { update_metrics (); }
@@ -149,25 +152,28 @@ namespace detail {
149152 assert (running_device_compute_jobs == 0 );
150153 }
151154
152- void executor::handle_command (const command_pkg& pkg, const std::vector<command_id>& dependencies) {
155+ bool executor::handle_command (const command_pkg& pkg, const std::vector<command_id>& dependencies) {
153156 switch (pkg.cmd ) {
154157 case command_type::HORIZON: create_job<horizon_job>(pkg, dependencies); break ;
155158 case command_type::PUSH: create_job<push_job>(pkg, dependencies, *btm); break ;
156159 case command_type::AWAIT_PUSH: create_job<await_push_job>(pkg, dependencies, *btm); break ;
157160 case command_type::TASK: {
158161 const auto & data = std::get<task_data>(pkg.data );
162+
163+ // A bit of a hack: We cannot be sure the main thread has reached the task definition yet, so we have to check it here
164+ if (!task_mngr.has_task (data.tid )) { return false ; }
165+
159166 auto tsk = task_mngr.get_task (data.tid );
160167 if (tsk->get_execution_target () == execution_target::HOST) {
161168 create_job<host_execute_job>(pkg, dependencies, h_queue, task_mngr);
162- break ;
163169 } else {
164170 create_job<device_execute_job>(pkg, dependencies, d_queue, task_mngr);
165- break ;
166171 }
167172 break ;
168173 }
169174 default : assert (!" Unexpected command" );
170175 }
176+ return true ;
171177 }
172178
173179 void executor::update_metrics () {
0 commit comments