CSE 121e: Week 04

Tasks

Your Task

Description

What you want to accomplish with this task is to solve a design problem. In the reading example, you can run a bunch of computations in a process, but if one request causes a crash, it takes everything down. This means that everyone else using that process for computations has a request fail. This is not good. As part of this redesign, you will want to use the Erlang programming principles learned earlier in the class to write easily read, understood, and, therefore, easily maintained code.

Before beginning this Task, make sure you have reviewed the concurrent programming course content.

The Process

Complete the following steps

  1. Download the math_procs.zip file.
  2. Using the ctemplate.erl file as a template (see the reading), update the arithmetic.erl file in the math_procs project to hold all of the code for processes that will be part of this task.
  3. Create 5 client functions modeled after the rpc function. Each may need more or fewer parameters than the rpc function. The client functions are
    1. factorial_of/2,
    2. add/3,
    3. subtract/3,
    4. multiply/3,
    5. divide/3,
  4. Create 5 stubbed out functions to be spawned. Model them after the loop/0 function in the ctemplate.erl file. The functions are
    1. factorializer/0,
    2. adder/0,
    3. subtracter/0,
    4. multiplier/0,
    5. divider/0,
  5. Create 5 start functions to spawn the stubbed-out functions. Model them after the start/0 function in the ctemplate.erl file. The functions are
    1. start_factorializer/0,
    2. start_adder/0,
    3. start_subtracter/0,
    4. start_multiplier/0,
    5. start_divider/0,
  6. Use the provided unit tests in the arithmetic.erl file to help you fill-in the code for each of the functions that are spawned.

Stretch Challenge (Optional)

  1. Modify your code to register the processes. This way you won't ever need to know the PIDs of any of your processes. You can see an example of registering processes in the setup portion of the unit tests.

Review

After completing the previous steps:

  1. Review one of the many possible solutions for this task. Do not expect to have found this solution out of the many available.
  2. Compare and contrast your code with the possible solutions’ code.
  3. Make note of any improvements you could make for future tasks.
  4. Make note of what your approach does well.