Explorar o código

fix unprotected nsched_ctxs read

Olivier Aumage %!s(int64=8) %!d(string=hai) anos
pai
achega
dd2916a3e7
Modificáronse 2 ficheiros con 5 adicións e 3 borrados
  1. 3 3
      src/core/sched_ctx.c
  2. 2 0
      src/core/workers.h

+ 3 - 3
src/core/sched_ctx.c

@@ -497,9 +497,6 @@ struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *p
 	struct _starpu_sched_ctx *sched_ctx = &config->sched_ctxs[id];
 	sched_ctx->id = id;
 
-	config->topology.nsched_ctxs++;
-	STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx_manag);
-
 	int nworkers = config->topology.nworkers;
 	int i;
 
@@ -605,6 +602,9 @@ struct _starpu_sched_ctx* _starpu_create_sched_ctx(struct starpu_sched_policy *p
 		}
 	}
 
+	(void)STARPU_ATOMIC_ADD(&config->topology.nsched_ctxs,1);
+	STARPU_PTHREAD_MUTEX_UNLOCK(&sched_ctx_manag);
+
 	return sched_ctx;
 }
 

+ 2 - 0
src/core/workers.h

@@ -587,6 +587,8 @@ static inline int _starpu_worker_get_nsched_ctxs(int workerid)
 /* Get the total number of sched_ctxs created till now */
 static inline unsigned _starpu_get_nsched_ctxs(void)
 {
+	/* topology.nsched_ctxs may be increased asynchronously in sched_ctx_create */
+	STARPU_RMB();
 	return _starpu_config.topology.nsched_ctxs;
 }