From 5bd48e074ad302b8c9ffa1b5f3e557785873f76f Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Thu, 4 Jul 2019 11:11:46 +0200
Subject: [PATCH] Also apply the same procedure for the black holes swallowing.

---
 src/runner.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/runner.c b/src/runner.c
index 8a966e9bc9..8cfcb03b20 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -3822,10 +3822,15 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
 
               lock_lock(&e->s->lock);
 
-              /* Finally, remove the gas particle from the system */
-              struct gpart *gp = p->gpart;
-              cell_remove_part(e, c, p, xp);
-              cell_remove_gpart(e, c, gp);
+              /* Re-check that the particle has not been removed
+               * by another thread before we do the deed. */
+              if (!part_is_inhibited(p, e)) {
+
+                /* Finally, remove the gas particle from the system */
+                struct gpart *gp = p->gpart;
+                cell_remove_part(e, c, p, xp);
+                cell_remove_gpart(e, c, gp);
+              }
 
               if (lock_unlock(&e->s->lock) != 0)
                 error("Failed to unlock the space!");
@@ -3860,10 +3865,15 @@ void runner_do_swallow(struct runner *r, struct cell *c, int timer) {
 
               lock_lock(&e->s->lock);
 
-              /* Finally, remove the gas particle from the system */
-              struct gpart *gp = p->gpart;
-              cell_remove_part(e, c, p, xp);
-              cell_remove_gpart(e, c, gp);
+              /* Re-check that the particle has not been removed
+               * by another thread before we do the deed. */
+              if (!part_is_inhibited(p, e)) {
+
+                /* Finally, remove the gas particle from the system */
+                struct gpart *gp = p->gpart;
+                cell_remove_part(e, c, p, xp);
+                cell_remove_gpart(e, c, gp);
+              }
 
               if (lock_unlock(&e->s->lock) != 0)
                 error("Failed to unlock the space!");
-- 
GitLab