-/**
- * @brief Internal function to kill a SIMIX process.
- *
- * This function may be called when a SIMCALL_PROCESS_KILL simcall occurs,
- * or directly for SIMIX internal purposes.
- *
- * @param process poor victim
- * @param issuer the process which has sent the PROCESS_KILL. Important to not schedule twice the same process.
- */
-void SIMIX_process_kill(smx_actor_t process, smx_actor_t issuer) {
-
- if (process->finished_) {
- XBT_DEBUG("Ignoring request to kill process %s@%s that is already dead", process->get_cname(),
- process->host_->get_cname());
- return;
- }
-
- XBT_DEBUG("Actor '%s'@%s is killing actor '%s'@%s", issuer->get_cname(),
- (issuer->host_ == nullptr ? "(null)" : issuer->host_->get_cname()), process->get_cname(),
- process->host_->get_cname());
-
- process->context_->iwannadie = true;
- process->blocked_ = false;
- process->suspended_ = false;
- process->exception = nullptr;
-
- // Forcefully kill the actor if its host is turned off. Not an HostFailureException because you should not survive that
- if (process->host_->is_off()) {
- /* HORRIBLE HACK: Don't throw an StopRequest exception in Java, because it breaks sometimes.
- *
- * It seems to break for the actors started from the Java world, with new Process()
- * while it works for the ones started from the C world, with the deployment file.
- * When it happens, the simulation stops brutally with a message "untrapped exception StopRequest".
- *
- * From what I understand, it works for the native actors because they have a nice try/catch block around their main
- * but I fail to have something like that for pure Java actors. That's probably a story of C->Java vs Java->C
- * calling conventions. The right solution may be to have try/catch(StopRequest) blocks around each native call in
- * JNI. ie, protect every Java->C++ call from C++ exceptions. But this sounds long and painful to do before we
- * switch to an automatic generator such as SWIG. For now, we don't throw here that exception that we sometimes fail
- * to catch.
- *
- * One of the unfortunate outcome is that the threads started from the deployment file are not stopped anymore.
- * Or maybe this is the actors stopping gracefully as opposed to the killed ones? Or maybe this is absolutely all
- * actors of the Java simulation? I'm not sure. Anyway. Because of them, the simulation hangs at the end, waiting
- * for them to stop but they won't. The current answer to that is very brutal:
- * we do a "exit(0)" to kill the JVM from the C code after the call to MSG_run(). Definitely unpleasant.
- */
-
- if (simgrid::kernel::context::factory_initializer == nullptr) // Only Java sets a factory_initializer, for now
- process->throw_exception(std::make_exception_ptr(simgrid::kernel::context::Context::StopRequest("Host failed")));
- }
-
- /* destroy the blocking synchro if any */
- if (process->waiting_synchro != nullptr) {
-
- simgrid::kernel::activity::ExecImplPtr exec =
- boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(process->waiting_synchro);
- simgrid::kernel::activity::CommImplPtr comm =
- boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(process->waiting_synchro);
- simgrid::kernel::activity::SleepImplPtr sleep =
- boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(process->waiting_synchro);
- simgrid::kernel::activity::RawImplPtr raw =
- boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(process->waiting_synchro);
- simgrid::kernel::activity::IoImplPtr io =
- boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(process->waiting_synchro);
-
- if (exec != nullptr) {
- if (exec->surf_action_) {
- exec->surf_action_->cancel();
- exec->surf_action_->unref();
- exec->surf_action_ = nullptr;
- }
- } else if (comm != nullptr) {
- process->comms.remove(process->waiting_synchro);
- comm->cancel();
- // Remove first occurrence of &process->simcall:
- auto i = boost::range::find(process->waiting_synchro->simcalls_, &process->simcall);
- if (i != process->waiting_synchro->simcalls_.end())
- process->waiting_synchro->simcalls_.remove(&process->simcall);
- } else if (sleep != nullptr) {
- if (sleep->surf_sleep)
- sleep->surf_sleep->cancel();
- sleep->post();
- } else if (raw != nullptr) {
- SIMIX_synchro_stop_waiting(process, &process->simcall);
-
- } else if (io != nullptr) {
- delete io.get();
- } else {
- simgrid::kernel::activity::ActivityImplPtr activity = process->waiting_synchro;
- xbt_die("Activity %s is of unknown type %s", activity->name_.c_str(),
- simgrid::xbt::demangle(typeid(activity).name()).get());
- }
-
- process->waiting_synchro = nullptr;
- }
- if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), process) ==
- end(simix_global->process_to_run) &&
- process != issuer) {
- XBT_DEBUG("Inserting %s in the to_run list", process->get_cname());
- simix_global->process_to_run.push_back(process);
- }
-}
-