X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/40af3dfdccd15dc232d8e7d9e9ad26655092cbfc..33d53861f6312ae42985bdc7011c396761125c3d:/examples/msg/mc/bugged2_liveness.c diff --git a/examples/msg/mc/bugged2_liveness.c b/examples/msg/mc/bugged2_liveness.c index 3f544cccee..15467bee43 100644 --- a/examples/msg/mc/bugged2_liveness.c +++ b/examples/msg/mc/bugged2_liveness.c @@ -1,3 +1,9 @@ +/***************** Producer/Consumer Algorithm *************************/ +/* This example implements a producer/consumer algorithm. */ +/* If consumer work before producer, message is empty */ +/***********************************************************************/ + + #include "msg/msg.h" #include "mc/mc.h" #include "xbt/automaton.h" @@ -5,7 +11,7 @@ #include "bugged2_liveness.h" #include "y.tab.c" -XBT_LOG_NEW_DEFAULT_CATEGORY(example_liveness_with_cycle, "my log messages"); +XBT_LOG_NEW_DEFAULT_CATEGORY(bugged2_liveness, "my log messages"); char* buffer; @@ -75,10 +81,13 @@ int producer(int argc, char *argv[]) char * my_mailbox = bprintf("%s", argv[1]); - //while(1) { + while(1) { /* Create message */ const char *mess = "message"; + + pready = 1; + XBT_INFO("pready = 1"); /* CS request */ XBT_INFO("Producer ask the request"); @@ -89,21 +98,21 @@ int producer(int argc, char *argv[]) MSG_task_receive(&grant, my_mailbox); MSG_task_destroy(grant); - pready = 1; - /* Push message (size of buffer = 1) */ buffer = strdup(mess); + produce = 1; + XBT_INFO("produce = 1"); + /* CS release */ MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator"); - produce = 1; + produce = 0; pready = 0; - //produce = 0; - //pready = 0; + XBT_INFO("pready et produce = 0"); - //} + } return 0; @@ -116,40 +125,43 @@ int consumer(int argc, char *argv[]) char *mess; - //while(1) { + while(1) { /* CS request */ XBT_INFO("Consumer ask the request"); MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator"); + cready = 1; + XBT_INFO("cready = 1"); + /* Wait the answer */ m_task_t grant = NULL; MSG_task_receive(&grant, my_mailbox); MSG_task_destroy(grant); - cready = 1; - /* Pop message */ mess = malloc(8*sizeof(char)); mess = strdup(buffer); buffer[0] = '\0'; - /* CS release */ - MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator"); - /* Display message */ XBT_INFO("Message : %s", mess); - if(strcmp(mess, "") != 0) + if(strcmp(mess, "") != 0){ consume = 1; + XBT_INFO("consume = 1"); + } - cready = 0; + /* CS release */ + MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator"); free(mess); - //consume = 0; - //cready = 0; + consume = 0; + cready = 0; + + XBT_INFO("cready et consume = 0"); - //} + } return 0;