X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/0ca1291c2f63ca6235f4b4885c48413a900aade4..82904dcc37f75453c571a1a74e67c1ba282ebe23:/src/msg/task.c diff --git a/src/msg/task.c b/src/msg/task.c index 2908b353fe..b0df136d09 100644 --- a/src/msg/task.c +++ b/src/msg/task.c @@ -159,25 +159,22 @@ MSG_error_t MSG_task_destroy(m_task_t task) smx_action_t action = NULL; xbt_assert((task != NULL), "Invalid parameter"); - /* why? if somebody is using, then you can't free! ok... but will return MSG_OK? when this task will be destroyed? isn't the user code wrong? */ - if (task->simdata->isused > 0) { - XBT_DEBUG("Cannot destroy task %p since somebody is using it", task); - return MSG_OK; + if (task->simdata->isused) { + /* the task is still being used, it may be an unfinished dsend */ + MSG_task_cancel(task); } #ifdef HAVE_TRACING TRACE_msg_task_destroy(task); #endif - if (task->name) - free(task->name); + xbt_free(task->name); action = task->simdata->compute; if (action) SIMIX_req_host_execution_destroy(action); /* parallel tasks only */ - if (task->simdata->host_list) - xbt_free(task->simdata->host_list); + xbt_free(task->simdata->host_list); /* free main structures */ xbt_free(task->simdata); @@ -189,7 +186,7 @@ MSG_error_t MSG_task_destroy(m_task_t task) /** \ingroup m_task_management * \brief Cancel a #m_task_t. - * \param task the taskt to cancel. If it was executed or transfered, it + * \param task the task to cancel. If it was executed or transfered, it stops the process that were working on it. */ MSG_error_t MSG_task_cancel(m_task_t task) @@ -198,13 +195,19 @@ MSG_error_t MSG_task_cancel(m_task_t task) if (task->simdata->compute) { SIMIX_req_host_execution_cancel(task->simdata->compute); - return MSG_OK; } - if (task->simdata->comm) { + else if (task->simdata->comm) { SIMIX_req_comm_cancel(task->simdata->comm); - return MSG_OK; + task->simdata->isused = 0; } - THROW_IMPOSSIBLE; + else { + static int warned = 0; + if (!warned) { + XBT_WARN("Cannot cancel a non-running task"); + warned = 1; + } + } + return MSG_OK; } /** \ingroup m_task_management