Assignment 4: Assignment for Topic 4, Exceptions & Threads
The goal of this assignment is to give you practice with the use of exceptions
and threads. You will extend the MML interpreter you implemented in the
last assignment with two new capabilities - the ability to halt and report error
messages and the ability to run multiple programs simultaneously.
Incorporating Exceptions
When writing a program there are many mistakes that a user can make that cause the program to be unrunnable. For example, the user can cause a divide by zero to occur or the user can write a bnz instruction to a label that does not exist. The rational reporting of errors would be a useful capability for your interpreter to have and exceptions are the right Java mechanism to implement it.
What you must do:
Incorporating Threads
At present the machine is capable of running only a single thread of execution. It would be useful to be able to run two separate threads of execution simultaneously sharing the same set of registers. In this part of the assignment you will use Java's built-in thread capabilities to implement this capability.
What you must do:
Modify Machine.java (and whatever other files you need to) so that multiple threads of execution (multiple machines) can be executing different programs simultaneously on the same register set.
Things you must consider:
Here are producer and consumer programs to test your modifications on. If implemented correctly the consumer should output 100, 200, 400 in that order.
A solution set for this assignment is now available.
Last Modified: Tuesday, October 02, 2001 12:58:05 PM