static int victim(int argc, char *argv[]) {
xbt_ex_t e;
- XBT_INFO("Let's get suspended.");
+ msg_error_t res = MSG_OK;
+
+ XBT_INFO("Let's work.");
TRY {
- MSG_process_suspend(MSG_process_self());
+ res = MSG_task_execute(MSG_task_create("Task", 1e14, 0, NULL));
+ if (res != MSG_OK) {
+ XBT_INFO("The MSG_task_execute caught the exception for me and returned %d)",res);
+ } else {
+ xbt_die("I was expecting an exception during my execution!");
+ }
} CATCH(e) {
XBT_INFO("The received exception resumed my execution. Good. Here is it: ----------------------->8----");
xbt_ex_display(&e);
xbt_ex_free(e);
}
- msg_error_t res = MSG_OK;
+
+ XBT_INFO("Let's get suspended.");
int gotit = 0;
+ TRY {
+ MSG_process_suspend(MSG_process_self());
+ } CATCH(e) {
+ XBT_INFO("The received exception resumed my suspension. Good. Here is it: ----------------------->8----");
+ xbt_ex_display(&e);
+ XBT_INFO("(end of the second exception) ----8<------------------------");
+ gotit = 1;
+ xbt_ex_free(e);
+ }
+ if(!gotit) {
+ xbt_die("I was expecting an exception during my suspension!");
+ }
+
XBT_INFO("Let's sleep for 10 seconds.");
TRY {
res = MSG_process_sleep(10);
+ if (res != MSG_OK) {
+ XBT_INFO("The MSG_process_sleep caught the exception for me and returned %d)",res);
+ } else {
+ xbt_die("I was expecting to get an exception during my nap.");
+ }
} CATCH(e) {
XBT_INFO("Got the second exception: ----------------------->8----");
xbt_ex_display(&e);
- XBT_INFO("(end of the second exception) ----8<------------------------");
+ XBT_INFO("(end of the third exception) ----8<------------------------");
xbt_ex_free(e);
}
- if (res != MSG_TASK_CANCELED)
- xbt_die("Sleep action not canceled through the exception. This is not a method. (retval: %d)",res);
- if (!gotit)
- xbt_die("I was expecting to get an exception during my nap.");
- XBT_INFO("My little nap got canceled through a raw exception. Excellent.");
+ XBT_INFO("Let's try a last time to do something on something");
+ MSG_process_sleep(10);
XBT_INFO("That's enough now. I quit.");
+
return 0;
}
XBT_INFO("Let's create a victim.");
victim_process = MSG_process_create("victim", victim, NULL, MSG_host_self());
+
+ XBT_INFO("Going to sleep for 1 second");
if (MSG_process_sleep(1) != MSG_OK)
xbt_die("What's going on??? I failed to sleep!");
XBT_INFO("Send a first exception (host failure)");
- SIMIX_process_throw(victim_process, host_error, 0, "Let's pretend that the host failed");
+ SIMIX_process_throw(victim_process, host_error, 0, "First Trick: Let's pretend that the host failed");
+
+
+ XBT_INFO("Sweet, let's prepare a second trick!");
+ XBT_INFO("Going to sleep for 2 seconds");
+
+ if (MSG_process_sleep(2) != MSG_OK)
+ xbt_die("What's going on??? I failed to sleep!");
+ XBT_INFO("Send a second exception (host failure)");
+ SIMIX_process_throw(victim_process, host_error, 0, "Second Trick: Let's pretend again that the host failed");
+
+ XBT_INFO("Sweet, let's prepare a third trick!");
+ XBT_INFO("Going to sleep for 3 seconds");
if (MSG_process_sleep(3) != MSG_OK)
xbt_die("What's going on??? I failed to sleep!");
- XBT_INFO("Send a second exception (cancellation)");
- SIMIX_process_throw(victim_process, cancel_error, 0, "Let's pretend this time that someone canceled something");
+ XBT_INFO("Send a third exception (cancellation)");
+ SIMIX_process_throw(victim_process, cancel_error, 0, "Third Trick: Let's pretend this time that someone canceled something");
XBT_INFO("OK, goodbye now.");
return 0;
! output sort
$ $SG_TEST_EXENV exception/exception ${srcdir:=.}/../platforms/platform.xml ${srcdir:=.}/exception/deployment_exception.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (1:terrorist@Jacquelin) Let's create a victim.
+> [ 0.000000] (2:victim@Jacquelin) Let's work.
+> [ 0.000000] (1:terrorist@Jacquelin) Going to sleep for 1 second
+> [ 1.000000] (1:terrorist@Jacquelin) Send a first exception (host failure)
+> [ 1.000000] (1:terrorist@Jacquelin) Sweet, let's prepare a second trick!
+> [ 1.000000] (1:terrorist@Jacquelin) Going to sleep for 2 seconds
+> [ 1.000000] (2:victim@Jacquelin) The MSG_task_execute caught the exception for me and returned 8)
+> [ 1.000000] (2:victim@Jacquelin) Let's get suspended.
+> [ 3.000000] (1:terrorist@Jacquelin) Send a second exception (host failure)
+> [ 3.000000] (1:terrorist@Jacquelin) Sweet, let's prepare a third trick!
+> [ 3.000000] (1:terrorist@Jacquelin) Going to sleep for 3 seconds
+> [ 3.000000] (2:victim@Jacquelin) The received exception resumed my suspension. Good. Here is it: ----------------------->8----
+> ** SimGrid: UNCAUGHT EXCEPTION received on exception/exception(2): category: action canceled; value: 0
+> ** Canceled
+> ** Thrown by () on process 0
+> [ 3.000000] (2:victim@Jacquelin) Canceled
+>
+> ** In SIMIX_execution_finish() at /home/alegrand/Work/SimGrid/simgrid-git/src/simix/smx_host.c:557
+> ** In SIMIX_post_host_execute() at /home/alegrand/Work/SimGrid/simgrid-git/src/simix/smx_host.c:604
+> ** In SIMIX_simcall_exit() at /home/alegrand/Work/SimGrid/simgrid-git/src/simix/popping.c:39
+> ** In SIMIX_run() at /home/alegrand/Work/SimGrid/simgrid-git/src/simix/smx_global.c:410
+> ** In MSG_main() at /home/alegrand/Work/SimGrid/simgrid-git/src/msg/msg_global.c:129
+> ** In main() at /home/alegrand/Work/SimGrid/simgrid-git/examples/msg/exception/exception.c:156
+> [ 3.000000] (2:victim@Jacquelin) (end of the second exception) ----8<------------------------
+> [ 3.000000] (2:victim@Jacquelin) Let's sleep for 10 seconds.
+> [ 6.000000] (1:terrorist@Jacquelin) Send a third exception (cancellation)
+> [ 6.000000] (1:terrorist@Jacquelin) OK, goodbye now.
+> [ 6.000000] (2:victim@Jacquelin) The MSG_process_sleep caught the exception for me and returned 8)
+> [ 6.000000] (2:victim@Jacquelin) Let's try a last time to do something on something
+> [ 16.000000] (2:victim@Jacquelin) That's enough now. I quit.
+> [ 16.000000] (0:@) Simulation time 16