/*********************************************************************/ /* From: Kuang-chun Tao */ /* Document for the Programming Techniques with processes for */ /* synchronous remote procedure call. */ /* Synchronous calls return a value which the caller waits for. The */ /* remote part of the procedure complete before the call returns. */ /* Fetch, Fetchcopy, and storeAt are example of remote procedure call*/ /* -s. A call is executed on one computer, but the substantive part */ /* of the procedure is executed on a different computer. In this case*/ /* , the remote procedure call is a synchronous. */ /*********************************************************************/ #include "amdc96.h" #include #define tag 1 Location my_loc; LocName my_name, L; void doFetch(Message m1, Location loc) { Message m2; if((m2 = amdc_getLoc(loc, tag)) != NULL) { amdc_sendToDest(m2, *(Destiny*)m1); amdc_freeMsg(m1); } else amdc_putLoc(loc, m1); } Message stub() { Message m; L = amdc_0DLocName(AMDC_SYMB_HASH); Destiny *d = (Destiny*)amdc_rawMsg(sizeof(Destiny)); amdc_initDest(d, my_name, tag, amdc_rawScript); amdc_sendToAsDo((Message)d, L, tag, (Script)doFetch); while((m = amdc_getLoc(my_loc, tag)) == NULL) amdc_pollBlock(); return m; } int Main() { Message x; my_loc = amdc_getMyLoc(); my_name = amdc_getNameOfLoc(my_loc); while(1) { x = stub(); if(x) printf("Synchronous remote procedure call is ok\n"); else printf("Synchronous remote procedure call is fail\n"); } }