+ while (!xbt_dynar_is_empty(comms)) {
+
+ int index = MSG_comm_waitany(comms);
+ msg_comm_t finished_comm = xbt_dynar_get_as(comms, index, msg_comm_t);
+ channel* ch;
+
+ for (ch = chan ; ch->comm != finished_comm ; ++ch)
+ /* nop */;
+
+ comm_check_n_destroy(ch->comm);
+ if (strcmp(MSG_task_get_name(ch->task), "finalize")) {
+ XBT_DEBUG("received message on %s", ch->mbox);
+ ch->received.push(ch->task);
+ ch->task = NULL;
+ ch->comm = MSG_task_irecv(&ch->task, ch->mbox);
+ xbt_dynar_set_as(comms, index, msg_comm_t, ch->comm);
+ } else {
+ XBT_DEBUG("received finalize on %s", ch->mbox);
+ MSG_task_destroy(ch->task);
+ ch->task = NULL;
+ ch->comm = NULL;
+ xbt_dynar_remove_at(comms, index, NULL);
+ }
+
+ }
+ xbt_dynar_free(&comms);