0

For an assigment, I have to create basic processor modules and allow them to exchange double values between each other. The modules will have the public function step(), which advances the execution of their program by one instruction. The modules are held in a HashMap, which the main program iterates over, ensuring that each (active) module can execute one instruction per cycle.

The way I plan to handle the inter-module communication is to create input-/output data fields inside each module, which are linked by the main program to all the other modules, acting as pipes between the modules. So when a processor module sets an ouput data field, the main program is notified, which then finds the module that output field is linked to and writes the value into the corresponding input data field of the receiving module and clears the output field from the sending module.

If a module wants to read from an input field that hasn't been set yet (== Double.NaN), or if a module wants to write to an output field that still holds a value (!= Double.NaN), the main program is notified as well and puts the module in question to sleep until the data field that is blocking the module is set/reset.

My question is, is this a reasonable approach to handling inter-process communication or should I change something. And if it is, how do I go about notifiying the main program in a way that allows it to put a module to sleep and resume it later on?

  • Are you talking about spring-batch? – Qingfei Yuan Jun 06 '19 at 14:57
  • No, sorry, I don't know what you are talking about. I recreated a basic ARM processor in java and now I have to run multiple instances of this processor in parallel and allow them to exchange double values with each other. I could just let them throw exceptions if they try to read/write registers that have not been set/ have been set, but I'd like to make the program more robust by having the processors wait until the register they try to read from/write to have been set/reset. – UmBottesWillen Jun 06 '19 at 15:02
  • 3
    Seems you are trying to communicate between different threads. Please refer to https://stackoverflow.com/questions/6916398/communicating-between-two-threads – Qingfei Yuan Jun 06 '19 at 15:05

0 Answers0