瀏覽代碼

core: do not create a sched_ctx when the user uses invalid worker IDs

This might prevent weird behaviours when invalid worker IDs are used. For
example this results in a deadlock in app_drivent_test.c. No regressions
for the sched_ctx examples.
Samuel Pitoiset 9 年之前
父節點
當前提交
bed5c8e317
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      src/core/sched_ctx.c

+ 15 - 0
src/core/sched_ctx.c

@@ -791,6 +791,21 @@ unsigned starpu_sched_ctx_create(int *workerids, int nworkers, const char *sched
 	}
 	va_end(varg_list);
 
+	if (workerids && nworkers != -1)
+	{
+		/* Make sure the user doesn't use invalid worker IDs. */
+		unsigned num_workers = starpu_worker_get_count();
+		for (int i = 0; i < nworkers; i++)
+		{
+			if (workerids[i] < 0 || workerids[i] >= num_workers)
+			{
+				_STARPU_ERROR("Invalid worker ID (%d) specified!\n",
+					      workerids[i]);
+				return STARPU_NMAX_SCHED_CTXS;
+			}
+		}
+	}
+
 	struct _starpu_sched_ctx *sched_ctx = NULL;
 	sched_ctx = _starpu_create_sched_ctx(sched_policy, workerids, nworkers, 0, sched_ctx_name, min_prio_set, min_prio, max_prio_set, max_prio, awake_workers, init_sched);
 	sched_ctx->hierarchy_level = hierarchy_level;