Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'stable'
[simgrid.git] / src / kernel / activity / CommImpl.cpp
1 /* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <simgrid/Exception.hpp>
7 #include <simgrid/kernel/routing/NetPoint.hpp>
8 #include <simgrid/modelchecker.h>
9 #include <simgrid/s4u/Host.hpp>
10
11 #include "src/kernel/activity/CommImpl.hpp"
12 #include "src/kernel/activity/MailboxImpl.hpp"
13 #include "src/kernel/context/Context.hpp"
14 #include "src/kernel/resource/CpuImpl.hpp"
15 #include "src/kernel/resource/LinkImpl.hpp"
16 #include "src/kernel/resource/StandardLinkImpl.hpp"
17 #include "src/mc/mc_replay.hpp"
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ker_network, kernel, "Kernel network-related synchronization");
20
21 XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t src, smx_mailbox_t mbox, double task_size,
22                                            double rate, unsigned char* src_buff, size_t src_buff_size,
23                                            bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
24                                            void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
25                                            void* data, double timeout)
26 {
27   simgrid::kernel::activity::ActivityImplPtr comm = simcall_HANDLER_comm_isend(
28       simcall, src, mbox, task_size, rate, src_buff, src_buff_size, match_fun, nullptr, copy_data_fun, data, false);
29   simcall->mc_value_ = 0;
30   comm->wait_for(simcall->issuer_, timeout);
31 }
32
33 XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr simcall_HANDLER_comm_isend(
34     smx_simcall_t /*simcall*/, smx_actor_t src_proc, smx_mailbox_t mbox, double task_size, double rate,
35     unsigned char* src_buff, size_t src_buff_size,
36     bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
37     void (*clean_fun)(void*), // used to free the synchro in case of problem after a detached send
38     void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), // used to copy data if not default one
39     void* data, bool detached)
40 {
41   XBT_DEBUG("send from mailbox %p", mbox);
42
43   /* Prepare a synchro describing us, so that it gets passed to the user-provided filter of other side */
44   simgrid::kernel::activity::CommImplPtr this_comm(
45       new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::SEND));
46
47   /* Look for communication synchro matching our needs. We also provide a description of
48    * ourself so that the other side also gets a chance of choosing if it wants to match with us.
49    *
50    * If it is not found then push our communication into the rendez-vous point */
51   simgrid::kernel::activity::CommImplPtr other_comm =
52       mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::RECEIVE, match_fun, data, this_comm,
53                                /*done*/ false, /*remove_matching*/ true);
54
55   if (not other_comm) {
56     other_comm = std::move(this_comm);
57
58     if (mbox->is_permanent()) {
59       // this mailbox is for small messages, which have to be sent right now
60       other_comm->set_state(simgrid::kernel::activity::State::READY);
61       other_comm->dst_actor_ = mbox->get_permanent_receiver().get();
62       mbox->push_done(other_comm);
63       XBT_DEBUG("pushing a message into the permanent receive list %p, comm %p", mbox, other_comm.get());
64
65     } else {
66       mbox->push(other_comm);
67     }
68   } else {
69     XBT_DEBUG("Receive already pushed");
70
71     other_comm->set_state(simgrid::kernel::activity::State::READY);
72   }
73
74   if (detached) {
75     other_comm->detach();
76     other_comm->clean_fun = clean_fun;
77   } else {
78     other_comm->clean_fun = nullptr;
79     src_proc->activities_.emplace_back(other_comm);
80   }
81
82   /* Setup the communication synchro */
83   other_comm->src_actor_ = src_proc;
84   other_comm->src_data_  = data;
85   (*other_comm).set_src_buff(src_buff, src_buff_size).set_size(task_size).set_rate(rate);
86
87   other_comm->match_fun     = match_fun;
88   other_comm->copy_data_fun = copy_data_fun;
89
90   if (MC_is_active() || MC_record_replay_is_active())
91     other_comm->set_state(simgrid::kernel::activity::State::RUNNING);
92   else
93     other_comm->start();
94
95   return (detached ? nullptr : other_comm);
96 }
97
98 XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox,
99                                            unsigned char* dst_buff, size_t* dst_buff_size,
100                                            bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
101                                            void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t),
102                                            void* data, double timeout, double rate)
103 {
104   simgrid::kernel::activity::ActivityImplPtr comm = simcall_HANDLER_comm_irecv(
105       simcall, receiver, mbox, dst_buff, dst_buff_size, match_fun, copy_data_fun, data, rate);
106   simcall->mc_value_ = 0;
107   comm->wait_for(simcall->issuer_, timeout);
108 }
109
110 XBT_PRIVATE simgrid::kernel::activity::ActivityImplPtr
111 simcall_HANDLER_comm_irecv(smx_simcall_t /*simcall*/, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff,
112                            size_t* dst_buff_size, bool (*match_fun)(void*, void*, simgrid::kernel::activity::CommImpl*),
113                            void (*copy_data_fun)(simgrid::kernel::activity::CommImpl*, void*, size_t), void* data,
114                            double rate)
115 {
116   simgrid::kernel::activity::CommImplPtr this_synchro(
117       new simgrid::kernel::activity::CommImpl(simgrid::kernel::activity::CommImpl::Type::RECEIVE));
118   XBT_DEBUG("recv from mbox %p. this_synchro=%p", mbox, this_synchro.get());
119
120   simgrid::kernel::activity::CommImplPtr other_comm;
121   // communication already done, get it inside the list of completed comms
122   if (mbox->is_permanent() && mbox->has_some_done_comm()) {
123     XBT_DEBUG("We have a comm that has probably already been received, trying to match it, to skip the communication");
124     // find a match in the list of already received comms
125     other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
126                                           this_synchro, /*done*/ true,
127                                           /*remove_matching*/ true);
128     // if not found, assume the receiver came first, register it to the mailbox in the classical way
129     if (not other_comm) {
130       XBT_DEBUG("We have messages in the permanent receive list, but not the one we are looking for, pushing request "
131                 "into list");
132       other_comm = std::move(this_synchro);
133       mbox->push(other_comm);
134     } else {
135       if (other_comm->surf_action_ && other_comm->get_remaining() < 1e-12) {
136         XBT_DEBUG("comm %p has been already sent, and is finished, destroy it", other_comm.get());
137         other_comm->set_state(simgrid::kernel::activity::State::DONE);
138         other_comm->set_mailbox(nullptr);
139       }
140     }
141   } else {
142     /* Prepare a comm describing us, so that it gets passed to the user-provided filter of other side */
143
144     /* Look for communication activity matching our needs. We also provide a description of
145      * ourself so that the other side also gets a chance of choosing if it wants to match with us.
146      *
147      * If it is not found then push our communication into the rendez-vous point */
148     other_comm = mbox->find_matching_comm(simgrid::kernel::activity::CommImpl::Type::SEND, match_fun, data,
149                                           this_synchro, /*done*/ false,
150                                           /*remove_matching*/ true);
151
152     if (other_comm == nullptr) {
153       XBT_DEBUG("Receive pushed first (%zu comm enqueued so far)", mbox->size());
154       other_comm = std::move(this_synchro);
155       mbox->push(other_comm);
156     } else {
157       XBT_DEBUG("Match my %p with the existing %p", this_synchro.get(), other_comm.get());
158
159       other_comm->set_state(simgrid::kernel::activity::State::READY);
160     }
161     receiver->activities_.emplace_back(other_comm);
162   }
163
164   /* Setup communication synchro */
165   other_comm->dst_actor_ = receiver;
166   other_comm->dst_data_  = data;
167   other_comm->set_dst_buff(dst_buff, dst_buff_size);
168
169   if (rate > -1.0 && (other_comm->get_rate() < 0.0 || rate < other_comm->get_rate()))
170     other_comm->set_rate(rate);
171
172   other_comm->match_fun     = match_fun;
173   other_comm->copy_data_fun = copy_data_fun;
174
175   if (MC_is_active() || MC_record_replay_is_active()) {
176     other_comm->set_state(simgrid::kernel::activity::State::RUNNING);
177     return other_comm;
178   }
179   other_comm->start();
180   return other_comm;
181 }
182
183 void simcall_HANDLER_comm_wait(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm, double timeout)
184 {
185   comm->wait_for(simcall->issuer_, timeout);
186 }
187
188 bool simcall_HANDLER_comm_test(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comm)
189 {
190   return comm->test(simcall->issuer_);
191 }
192
193 ssize_t simcall_HANDLER_comm_testany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count)
194 {
195   std::vector<simgrid::kernel::activity::ActivityImpl*> comms_vec(comms, comms + count);
196   return simgrid::kernel::activity::ActivityImpl::test_any(simcall->issuer_, comms_vec);
197 }
198
199 void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, simgrid::kernel::activity::CommImpl* comms[], size_t count,
200                                   double timeout)
201 {
202   std::vector<simgrid::kernel::activity::CommImpl*> comms_vec(comms, comms + count);
203   simgrid::kernel::activity::CommImpl::wait_any_for(simcall->issuer_, comms_vec, timeout);
204 }
205
206 /******************************************************************************/
207 /*                    SIMIX_comm_copy_data callbacks                       */
208 /******************************************************************************/
209 // XBT_ATTRIB_DEPRECATED_v333
210 void SIMIX_comm_set_copy_data_callback(void (*callback)(simgrid::kernel::activity::CommImpl*, void*, size_t))
211 {
212   simgrid::kernel::activity::CommImpl::set_copy_data_callback(callback);
213 }
214
215 // XBT_ATTRIB_DEPRECATED_v333
216 void SIMIX_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
217 {
218   simgrid::s4u::Comm::copy_buffer_callback(comm, buff, buff_size);
219 }
220
221 // XBT_ATTRIB_DEPRECATED_v333
222 void SIMIX_comm_copy_pointer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff, size_t buff_size)
223 {
224   simgrid::s4u::Comm::copy_pointer_callback(comm, buff, buff_size);
225 }
226
227 namespace simgrid {
228 namespace kernel {
229 namespace activity {
230 xbt::signal<void(CommImpl const&)> CommImpl::on_start;
231 xbt::signal<void(CommImpl const&)> CommImpl::on_completion;
232
233 void (*CommImpl::copy_data_callback_)(CommImpl*, void*, size_t) = &s4u::Comm::copy_pointer_callback;
234
235 void CommImpl::set_copy_data_callback(void (*callback)(CommImpl*, void*, size_t))
236 {
237   copy_data_callback_ = callback;
238 }
239
240 CommImpl& CommImpl::set_size(double size)
241 {
242   size_ = size;
243   return *this;
244 }
245
246 CommImpl& CommImpl::set_rate(double rate)
247 {
248   rate_ = rate;
249   return *this;
250 }
251 CommImpl& CommImpl::set_mailbox(MailboxImpl* mbox)
252 {
253   mbox_ = mbox;
254   return *this;
255 }
256
257 CommImpl& CommImpl::set_src_buff(unsigned char* buff, size_t size)
258 {
259   src_buff_      = buff;
260   src_buff_size_ = size;
261   return *this;
262 }
263
264 CommImpl& CommImpl::set_dst_buff(unsigned char* buff, size_t* size)
265 {
266   dst_buff_      = buff;
267   dst_buff_size_ = size;
268   return *this;
269 }
270
271 CommImpl& CommImpl::detach()
272 {
273   detached_ = true;
274   return *this;
275 }
276
277 CommImpl::CommImpl(s4u::Host* from, s4u::Host* to, double bytes) : size_(bytes), detached_(true), from_(from), to_(to)
278 {
279   set_state(State::READY);
280 }
281
282 CommImpl::~CommImpl()
283 {
284   XBT_DEBUG("Really free communication %p in state %s (detached = %d)", this, get_state_str(), detached_);
285
286   cleanup_surf();
287
288   if (detached_ && get_state() != State::DONE) {
289     /* the communication has failed and was detached:
290      * we have to free the buffer */
291     if (clean_fun)
292       clean_fun(src_buff_);
293     src_buff_ = nullptr;
294   } else if (mbox_) {
295     mbox_->remove(this);
296   }
297 }
298
299 /**  @brief Starts the simulation of a communication synchro. */
300 CommImpl* CommImpl::start()
301 {
302   /* If both the sender and the receiver are already there, start the communication */
303   if (get_state() == State::READY) {
304     from_ = from_ != nullptr ? from_ : src_actor_->get_host();
305     to_   = to_ != nullptr ? to_ : dst_actor_->get_host();
306     /* Getting the network_model from the origin host
307      * Valid while we have a single network model, otherwise we would need to change this function to first get the
308      * routes and later create the respective surf actions */
309     auto net_model = from_->get_netpoint()->get_englobing_zone()->get_network_model();
310
311     surf_action_ = net_model->communicate(from_, to_, size_, rate_);
312     surf_action_->set_activity(this);
313     surf_action_->set_category(get_tracing_category());
314     set_start_time(surf_action_->get_start_time());
315     set_state(State::RUNNING);
316     on_start(*this);
317
318     XBT_DEBUG("Starting communication %p from '%s' to '%s' (surf_action: %p; state: %s)", this, from_->get_cname(),
319               to_->get_cname(), surf_action_, get_state_str());
320
321     /* If a link is failed, detect it immediately */
322     if (surf_action_->get_state() == resource::Action::State::FAILED) {
323       XBT_DEBUG("Communication from '%s' to '%s' failed to start because of a link failure", from_->get_cname(),
324                 to_->get_cname());
325       set_state(State::LINK_FAILURE);
326       post();
327
328     } else if ((src_actor_ != nullptr && src_actor_->is_suspended()) ||
329                (dst_actor_ != nullptr && dst_actor_->is_suspended())) {
330       /* If any of the actor is suspended, create the synchro but stop its execution,
331          it will be restarted when the sender actor resume */
332       if (src_actor_->is_suspended())
333         XBT_DEBUG("The communication is suspended on startup because src (%s@%s) was suspended since it initiated the "
334                   "communication",
335                   src_actor_->get_cname(), src_actor_->get_host()->get_cname());
336       else
337         XBT_DEBUG("The communication is suspended on startup because dst (%s@%s) was suspended since it initiated the "
338                   "communication",
339                   dst_actor_->get_cname(), dst_actor_->get_host()->get_cname());
340
341       surf_action_->suspend();
342     }
343   }
344
345   return this;
346 }
347
348 std::vector<s4u::Link*> CommImpl::get_traversed_links() const
349 {
350   xbt_assert(get_state() != State::WAITING, "You cannot use %s() if your communication is not ready (%s)", __FUNCTION__,
351              get_state_str());
352   std::vector<s4u::Link*> vlinks;
353   XBT_ATTRIB_UNUSED double res = 0;
354   from_->route_to(to_, vlinks, &res);
355   return vlinks;
356 }
357
358 /** @brief Copy the communication data from the sender's buffer to the receiver's one  */
359 void CommImpl::copy_data()
360 {
361   size_t buff_size = src_buff_size_;
362   /* If there is no data to copy then return */
363   if (not src_buff_ || not dst_buff_ || copied_)
364     return;
365
366   XBT_DEBUG("Copying comm %p data from %s (%p) -> %s (%p) (%zu bytes)", this,
367             src_actor_ ? src_actor_->get_host()->get_cname() : "a finished actor", src_buff_,
368             dst_actor_ ? dst_actor_->get_host()->get_cname() : "a finished actor", dst_buff_, buff_size);
369
370   /* Copy at most dst_buff_size bytes of the message to receiver's buffer */
371   if (dst_buff_size_) {
372     buff_size = std::min(buff_size, *dst_buff_size_);
373
374     /* Update the receiver's buffer size to the copied amount */
375     *dst_buff_size_ = buff_size;
376   }
377
378   if (buff_size > 0) {
379     if (copy_data_fun)
380       copy_data_fun(this, src_buff_, buff_size);
381     else
382       copy_data_callback_(this, src_buff_, buff_size);
383   }
384
385   /* Set the copied flag so we copy data only once */
386   /* (this function might be called from both communication ends) */
387   copied_ = true;
388 }
389
390 bool CommImpl::test(actor::ActorImpl* issuer)
391 {
392   if ((MC_is_active() || MC_record_replay_is_active()) && src_actor_ && dst_actor_)
393     set_state(State::DONE);
394   return ActivityImpl::test(issuer);
395 }
396
397 void CommImpl::wait_for(actor::ActorImpl* issuer, double timeout)
398 {
399   XBT_DEBUG("CommImpl::wait_for(%g), %p, state %s", timeout, this, get_state_str());
400
401   /* Associate this simcall to the wait synchro */
402   register_simcall(&issuer->simcall_);
403   if (MC_is_active() || MC_record_replay_is_active()) {
404     int idx = issuer->simcall_.mc_value_;
405     if (idx == 0) {
406       set_state(State::DONE);
407     } else {
408       /* If we reached this point, the wait simcall must have a timeout */
409       /* Otherwise it shouldn't be enabled and executed by the MC */
410       if (timeout < 0.0)
411         THROW_IMPOSSIBLE;
412       set_state(issuer == src_actor_ ? State::SRC_TIMEOUT : State::DST_TIMEOUT);
413     }
414     finish();
415     return;
416   }
417   ActivityImpl::wait_for(issuer, timeout);
418 }
419
420 void CommImpl::wait_any_for(actor::ActorImpl* issuer, const std::vector<CommImpl*>& comms, double timeout)
421 {
422   std::vector<ActivityImpl*> activities(comms.begin(), comms.end());
423   ActivityImpl::wait_any_for(issuer, activities, timeout);
424 }
425
426 void CommImpl::suspend()
427 {
428   /* FIXME: shall we suspend also the timeout synchro? */
429   if (surf_action_)
430     surf_action_->suspend();
431   /* if not created yet, the action will be suspended on creation, in CommImpl::start() */
432 }
433
434 void CommImpl::resume()
435 {
436   /*FIXME: check what happen with the timeouts */
437   if (surf_action_)
438     surf_action_->resume();
439   /* in the other case, the synchro were not really suspended yet, see CommImpl::suspend() and CommImpl::start() */
440 }
441
442 void CommImpl::cancel()
443 {
444   /* if the synchro is a waiting state means that it is still in a mbox so remove from it and delete it */
445   if (get_state() == State::WAITING) {
446     if (not detached_) {
447       mbox_->remove(this);
448       set_state(State::CANCELED);
449     }
450   } else if (not MC_is_active() /* when running the MC there are no surf actions */
451              && not MC_record_replay_is_active() && (get_state() == State::READY || get_state() == State::RUNNING)) {
452     surf_action_->cancel();
453   }
454 }
455
456 /** @brief This is part of the cleanup process, probably an internal command */
457 void CommImpl::cleanup_surf()
458 {
459   clean_action();
460
461   if (src_timeout_) {
462     src_timeout_->unref();
463     src_timeout_ = nullptr;
464   }
465
466   if (dst_timeout_) {
467     dst_timeout_->unref();
468     dst_timeout_ = nullptr;
469   }
470 }
471
472 void CommImpl::post()
473 {
474   on_completion(*this);
475
476   /* Update synchro state */
477   if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FINISHED)
478     set_state(State::SRC_TIMEOUT);
479   else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FINISHED)
480     set_state(State::DST_TIMEOUT);
481   else if (src_timeout_ && src_timeout_->get_state() == resource::Action::State::FAILED)
482     set_state(State::SRC_HOST_FAILURE);
483   else if (dst_timeout_ && dst_timeout_->get_state() == resource::Action::State::FAILED)
484     set_state(State::DST_HOST_FAILURE);
485   else if (surf_action_ && surf_action_->get_state() == resource::Action::State::FAILED) {
486     set_state(State::LINK_FAILURE);
487   } else
488     set_state(State::DONE);
489
490   XBT_DEBUG("CommImpl::post(): comm %p, state %s, src_proc %p, dst_proc %p, detached: %d", this, get_state_str(),
491             src_actor_.get(), dst_actor_.get(), detached_);
492
493   /* destroy the surf actions associated with the Simix communication */
494   cleanup_surf();
495
496   /* Answer all simcalls associated with the synchro */
497   finish();
498 }
499 void CommImpl::set_exception(actor::ActorImpl* issuer)
500 {
501   switch (get_state()) {
502     case State::FAILED:
503       issuer->exception_ = std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
504       break;
505     case State::SRC_TIMEOUT:
506       issuer->exception_ =
507           std::make_exception_ptr(TimeoutException(XBT_THROW_POINT, "Communication timeouted because of the sender"));
508       break;
509
510     case State::DST_TIMEOUT:
511       issuer->exception_ =
512           std::make_exception_ptr(TimeoutException(XBT_THROW_POINT, "Communication timeouted because of the receiver"));
513       break;
514
515     case State::SRC_HOST_FAILURE:
516       if (issuer == src_actor_)
517         issuer->context_->set_wannadie();
518       else {
519         set_state(State::FAILED);
520         issuer->exception_ = std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
521       }
522       break;
523
524     case State::DST_HOST_FAILURE:
525       if (issuer == dst_actor_)
526         issuer->context_->set_wannadie();
527       else {
528         set_state(State::FAILED);
529         issuer->exception_ = std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Remote peer failed"));
530       }
531       break;
532
533     case State::LINK_FAILURE:
534       XBT_DEBUG("Link failure in synchro %p between '%s' and '%s': posting an exception to the issuer: %s (%p) "
535                 "detached:%d",
536                 this, src_actor_ ? src_actor_->get_host()->get_cname() : nullptr,
537                 dst_actor_ ? dst_actor_->get_host()->get_cname() : nullptr, issuer->get_cname(), issuer, detached_);
538       if (src_actor_ == issuer) {
539         XBT_DEBUG("I'm source");
540       } else if (dst_actor_ == issuer) {
541         XBT_DEBUG("I'm dest");
542       } else {
543         XBT_DEBUG("I'm neither source nor dest");
544       }
545       set_state(State::FAILED);
546       issuer->throw_exception(std::make_exception_ptr(NetworkFailureException(XBT_THROW_POINT, "Link failure")));
547       break;
548
549     case State::CANCELED:
550       if (issuer == dst_actor_)
551         issuer->exception_ =
552             std::make_exception_ptr(CancelException(XBT_THROW_POINT, "Communication canceled by the sender"));
553       else
554         issuer->exception_ =
555             std::make_exception_ptr(CancelException(XBT_THROW_POINT, "Communication canceled by the receiver"));
556       break;
557
558     default:
559       xbt_assert(get_state() == State::DONE, "Internal error in CommImpl::finish(): unexpected synchro state %s",
560                  get_state_str());
561   }
562 }
563
564 void CommImpl::finish()
565 {
566   XBT_DEBUG("CommImpl::finish() in state %s", get_state_str());
567   /* If the synchro is still in a rendez-vous point then remove from it */
568   if (mbox_)
569     mbox_->remove(this);
570
571   if (get_state() == State::DONE)
572     copy_data();
573
574   while (not simcalls_.empty()) {
575     smx_simcall_t simcall = simcalls_.front();
576     simcalls_.pop_front();
577
578     /* If a waitany simcall is waiting for this synchro to finish, then remove it from the other synchros in the waitany
579      * list. Afterwards, get the position of the actual synchro in the waitany list and return it as the result of the
580      * simcall */
581
582     if (simcall->call_ == simix::Simcall::NONE) // FIXME: maybe a better way to handle this case
583       continue;                                 // if actor handling comm is killed
584
585     handle_activity_waitany(simcall);
586
587     /* Check out for errors */
588
589     if (not simcall->issuer_->get_host()->is_on()) {
590       simcall->issuer_->context_->set_wannadie();
591     } else {
592       // Do not answer to dying actors
593       if (not simcall->issuer_->context_->wannadie()) {
594         set_exception(simcall->issuer_);
595         simcall->issuer_->simcall_answer();
596       }
597     }
598
599     simcall->issuer_->waiting_synchro_ = nullptr;
600     simcall->issuer_->activities_.remove(this);
601     if (detached_) {
602       if (simcall->issuer_ != dst_actor_ && dst_actor_ != nullptr)
603         dst_actor_->activities_.remove(this);
604       if (simcall->issuer_ != src_actor_ && src_actor_ != nullptr)
605         src_actor_->activities_.remove(this);
606     }
607   }
608 }
609
610 } // namespace activity
611 } // namespace kernel
612 } // namespace simgrid