/************************************************************************/ /* From:Kuang-chun Tao */ /* Document for the Programming Techniques with Processes for the Job */ /* Jars. */ /* An importment use of an unordered queue is as a job jar. The messages*/ /* with the same tag in a table at a location are kept in a queue. If */ /* you send more than one message to a location to be stored, they will */ /* be queued. Although the queue at the location is FIFO, you are not */ /* guaranteed to get a FIFO queue between two processes this way. The */ /* problem is that the storeAt procedure does not wait for the message */ /* to be actually placed in the table at the location before it returns.*/ /* AMDC's run time system does not promise that message will be */ /* delivered in the order sent. Anyway, if delivery in the order sent */ /* is not essential, you can use storeAt and fetch to implement a named */ /* queue. The message in the job jar indicate task to perform. Whenever */ /* a process needs more work to do, it fetches a message out of the job */ /* jar. Whenever a process creates more work to do, it drops messages */ /* in the job jars. For example, the memo system provides communication */ /* among parallel processes through a shared directory of unordered */ /* queues. In Memo, the queues are called folders and appear only in the*/ /* directory associated with names. A folder names consist of a "symbol"*/ /* and three integers, allowing the simulation of up-to-three-dim arrays*/ /* of folders */ /************************************************************************/ #include "amdc96.h" #include #define tag 1 #define JobJar AMDC_AbsoluteSymbol(1, AMDC_SYMB_HASH) Location my_loc; LocName my_name; void doFetch(Message m, Location loc) { Message p; if((p = amdc_getLoc(loc, tag)) != NULL) { amdc_sendToDest(p, *(Destiny*)m); amdc_freeMsg(m); } else amdc_putLoc(loc, m); } Message fetch(LocName L) { Destiny *d = (Destiny*)amdc_rawMsg(sizeof(Destiny)); Message p; amdc_initDest(d, my_name, tag, amdc_rawScript); amdc_sendToAsDo((Message)d, L, tag, (Script)doFetch); while((p = amdc_getLoc(my_loc, tag)) == NULL) amdc_pollBlock(); return p; } void storeAt(Message m, LocName L) { amdc_sendToAs(m, L, tag); } int Main() { LocName L; Message m, ps; my_loc = amdc_getMyLoc(); my_name = amdc_getNameOfLoc(my_loc); while(1) { L = amdc_0DLocName(JobJar); m = amdc_rawMsg(sizeof(int)); storeAt(m, L); ps = fetch(L); if(ps) printf("Process %d fetched a record\n", amdc_getMyId()); } }