CSCI P415/515 | Fri Jan 6 15:18:04 EST 2012 [SDJ] |
An observer process is monitoring asynchronous events. When it senses an event it increments a counter variable. In pseudocode:
Observer: while true do begin await EVENT; COUNT := COUNT + 1; end;A reporter process periodically prints the event tally and clears the counter.
Reporter: while true do begin wait INTERVAL seconds; print(TIME, COUNT); COUNT := 0; end;These higher level instructions must be compiled into a "machine-level" model whose atomic instructions can only:
The machine model, then, is a traditional one in which "memory" can only hold data, and in order to manipulate date, it must first be brought into the registers of the processor. At this level of atomicity, the processes are:
- MOV source, destination copies a word of data one location to another, but does not alter that data. The source and target locations may be processor registers or memory addresses.
- OP opnd1, opnd2, result performs an arithmetic-logical operation OP on operands opnd1 and opnd2 leaving the result in location result. Locations opnd1, opnd2 and result must all be processor registers.
- JMP label transfers control to another point in the program.
OBSERVER: {wait for EVENT to occur} MOV count, r1 -- retrieve the value of COUNT ADD 1, r1, r1 -- increment it MOV r1, count -- store the result JMP OBSERVER REPORTER: {wait for an INTERVAL of time} MOV count, r1 -- retrieve the value of COUNT MOV 0, count -- clear the global value {Print r1} -- log the value JMP REPORTER