diff --git a/src/task.c b/src/task.c
index 9d4be3aaa5aaa074b19f7a22bddab99629ef9085..6bc29730eddec091590687867fc5dd72bbb129ec 100644
--- a/src/task.c
+++ b/src/task.c
@@ -380,6 +380,11 @@ void task_unlock(struct task *t) {
       cell_munlocktree(cj);
       break;
 
+    case task_type_star_formation:
+      cell_unlocktree(ci);
+      cell_sunlocktree(ci);
+      cell_gunlocktree(ci);
+
     default:
       break;
   }
@@ -518,6 +523,21 @@ int task_lock(struct task *t) {
         cell_munlocktree(ci);
         return 0;
       }
+      break;
+
+    case task_type_star_formation:
+      /* Lock the gas, gravity and star particles */
+      if (ci->hydro.hold || ci->stars.hold || ci->grav.phold) return 0;
+      if (cell_locktree(ci) != 0) return 0;
+      if (cell_slocktree(ci) != 0) {
+        cell_unlocktree(ci);
+        return 0;
+      }
+      if (cell_glocktree(ci) != 0) {
+        cell_unlocktree(ci);
+        cell_sunlocktree(ci);
+        return 0;
+      }
 
     default:
       break;