Browse Source

Fix tag lock order. Hopefully fixes some hangs.

Samuel Thibault 13 years ago
parent
commit
dfcc89da57
2 changed files with 9 additions and 3 deletions
  1. 6 2
      src/core/dependencies/tags.c
  2. 3 1
      src/core/dependencies/tags.h

+ 6 - 2
src/core/dependencies/tags.c

@@ -224,8 +224,8 @@ void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t
 	struct _starpu_tag *tag_child = gettag_struct(id);
 
 	_starpu_spin_lock(&tag_child->lock);
-
 	struct _starpu_cg *cg = create_cg_tag(ndeps, tag_child);
+	_starpu_spin_unlock(&tag_child->lock);
 
 	STARPU_ASSERT(ndeps != 0);
 
@@ -240,7 +240,9 @@ void starpu_tag_declare_deps_array(starpu_tag_t id, unsigned ndeps, starpu_tag_t
 		struct _starpu_tag *tag_dep = gettag_struct(dep_id);
 		STARPU_ASSERT(tag_dep != tag_child);
 		_starpu_spin_lock(&tag_dep->lock);
+		_starpu_spin_lock(&tag_child->lock);
 		_starpu_tag_add_succ(tag_dep, cg);
+		_starpu_spin_unlock(&tag_child->lock);
 		_starpu_spin_unlock(&tag_dep->lock);
 	}
 
@@ -255,8 +257,8 @@ void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...)
 	struct _starpu_tag *tag_child = gettag_struct(id);
 
 	_starpu_spin_lock(&tag_child->lock);
-
 	struct _starpu_cg *cg = create_cg_tag(ndeps, tag_child);
+	_starpu_spin_unlock(&tag_child->lock);
 
 	STARPU_ASSERT(ndeps != 0);
 
@@ -274,7 +276,9 @@ void starpu_tag_declare_deps(starpu_tag_t id, unsigned ndeps, ...)
 		struct _starpu_tag *tag_dep = gettag_struct(dep_id);
 		STARPU_ASSERT(tag_dep != tag_child);
 		_starpu_spin_lock(&tag_dep->lock);
+		_starpu_spin_lock(&tag_child->lock);
 		_starpu_tag_add_succ(tag_dep, cg);
+		_starpu_spin_unlock(&tag_child->lock);
 		_starpu_spin_unlock(&tag_dep->lock);
 	}
 	va_end(pa);

+ 3 - 1
src/core/dependencies/tags.h

@@ -1,6 +1,6 @@
 /* StarPU --- Runtime system for heterogeneous multicore architectures.
  *
- * Copyright (C) 2009, 2010  Université de Bordeaux 1
+ * Copyright (C) 2009-2011  Université de Bordeaux 1
  * Copyright (C) 2010, 2011  Centre National de la Recherche Scientifique
  *
  * StarPU is free software; you can redistribute it and/or modify
@@ -47,6 +47,8 @@ struct _starpu_job;
 
 struct _starpu_tag
 {
+	/* Lock for this structure. Locking order is in dependency order: a tag
+	 * must not be locked before locking a tag it depends on */
 	struct _starpu_spinlock lock;
 	starpu_tag_t id; /* an identifier for the task */
 	enum _starpu_tag_state state;