UNC-CH COMP 590-059

Final Exam

Individual work
Due: Sunday 12/08 (11:59pm)

1) Program the Dining Philosopher problem in Rust. Test it well to convince yourself it does not deadlock or starve any philosopher, or have race conditions. I want each philosoper to keep count of how many times it eats, and how many times it thinks. I want the program to have a graceful way to end the philosophers cycling and to run until that signal is given. When the end signal happens, print the counts from each philosopher.

2) Write me a page explaining your design decisions. What Rust feature did you use to model forks, philosophers, eating, thinking, etc. Did you use channels? Did you use shared data? Explain your design.

I will create a canvas assignment for the exam so you can upload a zip file containing your code and also your writeup (as a text file).



Class Assignments


Assignment 8: Rust programming

Team work
Due: Monday 11/25 (11:59pm)

Write a Rust program that does the 3-process program we did in Erlang. Don't do the hot-swap version, just the basic initial one. This was the program that had a chain of 3 processes; it read a message from the keyboard and sent it down the chain, and each process tried to handle the message. If it could not handle it, the message was passed down the chain to the next handler.



Assignment 7: Go programming

Team work
Due: Sunday 11/10 (11:59pm)

Write a Go program that solves the Sleeping Barber problem. Submit it in Canvas as we have been doing, with a zip file containing all source files and a readme file naming all team members. Also make sure all team members are named in comments at the top of every source file.



Assignment 6: Elixir programming

Team work
Due: Sunday 10/27 (11:59pm)

In this assignment we will do some basic Elixir programming.

a) First, you have installed Elixir on your computing platform. Hopefully you have been following along in our class material and trying the examples we have looked it. You have figured out how to compile and run basic Elixir code, both in the iex shell and also using the compilers elixir and elixirc.

b) Then, for submission, write the 3 smaller Erlang programs from Assignment 3 and Assignment 5 (Assn 4 with hot swaps) as Elixir programs.

Put the Elixir source code files into a zip file for submission. Make sure to identify all of your team members for proper credit in a README file as well as comments in each source code file.



Assignment 5: Updateable Erlang processes

Team work
Due: Sunday 10/13 11:59pm

This assignment is a modification of the code you wrote for Assignment 4. As such you have one week to finish it, and its worth half of Assignment 4.

Recall that in Assignment 4 you had three servers running, arranged in a message passing chain. Modify this code by adding an "update" message to each server. When a server receives the atom "update" as a message, it should update itself to run the newest version of its code.

Make sure that when one server updates, the other ones do not... they should continue to run their current code until they get their own update message. The "update" message should not be propagated.

As before, put all your code files into one zipfile along with a README text file naming all team members. Also put comments into each code file with team member names. Then one team member will submit the zip file on behalf of the entire team.





Assignment 4: Erlang processes program

Team work
Due: Sunday 10/06 11:59pm

In this assignment we will write an Erlang program that spawns several processes to cooperatively solve the problem.

Write an Erlang program that will use the "send_recv" module we discusses in the video as a pattern or guide. You will write a chain of 3 "servers" which are processes that are in a chain communication pattern. Lets call for this discussion the servers serv1, serv2, and serv3. The head of the chain is serv1, which will be communicating with serv2; serv2 will communicate with serv3. The serv1 process will receieve messages (from the main function) and possibly send what it received on to serv2. The serv2 process will receieve messages from serv1 and possibly send what it received on to serv3; likewise, the serv3 process will receieve messages from serv2 but will not send any messages onward.

The basic specs are these:

-- all 3 server processes run potentially "forever" (except each will end when a halt message 
   is received)

-- each one will examine messages it receives looking for ones that
   it knows how to handle; on finding one, it will processes it as
   its job requires;  if a message does not match the pattern(s) 
   that it handles, the server process will pass that message down the chain.

-- serv1 will do much like the math servers from our example code.  It will intercept messages
   that are tuples of size 3 or size 2.  A size 3 tuple will have the first component the 
   atom 'add', 'sub', 'mult' or 'div', and the rest of the message will be 2 numbers.  
   Perform the indicated arithmetic operation with component 2 the left operand and component 
   3 the right operand.  In addition, a size 2 tuple will have the first component the atom 
   'neg' or 'sqrt' and the second component the numbers to apply the appropriate operation on.  
   For all messages, print an informative message indicating the operation, the operands, and 
   the result.  If the message does not match any of these patterns, then send the message 
   on to serv2. 

-- serv2 will intercept mesages that consist of lists, where the head element in the list
   is a number. if that number is an integer, then print out the sum of all elements in
   the list that are numbers.  If the head element of the list is a float, then compute and
   print the product of all the numbers in the list (integer or float).
   If the message does not match any of these patterns, then send the message on to serv3.

-- serv3 will get all the messages that the processes earlier in the chain
   dont want to handle.  If the message is a tuple of size 2, with the first component
   the atom 'error' then print "Error: " and the second component of the message tuple.
   For any other message keep a running count of the unprocessed messages.  Simply print 
   out "Not handled: " followed by the message; also bump up the unprocessed message count.  
   To do this you will need an accumulator that you pass to each successive recursive server 
   call.  This means the serv3 function you make into a process will use a helper recursive 
   function that takes one parameter (the accumulator) and starts with 0 as that parameter.

-- each server process is doing some printing.  Any output they make should have the first 
   part indetify the process doing the writing -- something like "(serv1) whatever the 
   output text is..."

-- in addition to the various different message patterns each server process will watch for,
   all 3 processes will also respond to a shut down message.  The message will be the single 
   atom 'halt' and the server behavior will be to forward the 'halt' message down the chain, 
   then print out that it is halting, and finally end its own execution (meaning do not recurse 
   for more message handling).  For the end of the chain, the serv3 process, which is counting 
   all messages not processed, print a note with the value of that counter before doing its 
   halt sequence.

The main function (let's call it "start/0") will repeatedly as the user to type a message as input, and will send the message to serv1 at the head on the chain. If the user types the atom 'all_done' then the main start function will end execution.

Feel free to embellish the program as you wish. Have fun with it.

This is team work. The team produces a common solution, and one group member submits the entire solution on behalf of all the group members. Put an erlang comment in your module source files naming all the group members (or naming the solo person doing the work if you are a team of 1). Also create a README text file with the team member names in it, as well as anything else you wish to comment about the assignment solution.
Put your source files and README into one zip file, and in Canvas, submit this single zip file.




Assignment 3: Basic Erlang Programming

Team work
Due: Tuesday 9/17 11:59pm

In this assignment we will get Erlang running on your computers, and then write two simple Erlang programs. The goal is to get familiar with Erlang syntax and with the Erlang functional programming style.

Follow the instructions (see the reading lists) to get Erlang installed on your laptop or other computer. Try the examples we have looked at in class, and get used to making source modules (with the .erl file type). Make sure you move around in the file system using the unix-ish "cd", "pwd", and "ls" commands; make sure you can compile the modules; make sure you can run the functions defined and exported by those modules.

Here is a short new erlang lesson: getting input from the keyboard. This is a small function that will get a number from the keyboard, and you may use this as you wish in the programs you write:

    get_numData() ->
        {ok, Num} = io:read("Enter a number: "),
        io:format("The number you entered is: ~w~n", [Num]).
This works using pattern matching, where the number typed by the user is bound to "Num" on the left side of the expression using io:read.

Once this all works, write these two Erlang programs. You can put them both in one module, along with any supporting functions; or if you would rather, you can write two different modules:

  1. Write an Erlang program that will take one number as input (you will get the number from the user typing it at the keyboard) and then do this computation:
        a) if the input is not an integer, print "not an integer"
    
        b) if the input integer is negative (smaller than 0), compute
           the absolute value of that integer raised to the 7th power... 
           and print that.
    
        c) if the input integer is 0, simply output the 0
    
        d) is the input integer is greater than 0 then decide if it is 
           a multiple of 7 or not; if it is a multiple of 7, print out 
           the 5th root of the integer; if its not a multiple of 7, then 
           print out the factorial of that integer.
    
    It ends after doing the correct thing with the input number. You may find math:pow(X,Y) useful... it returns a float, and it computed X raised to the Y power. Factorial is a function we defined in class (in a PPT).

  2. Use the program just written as a "loop" body, and repeat the get-input-then-compute cycle repeatedly. End this repetition when the user gives a 0 as input. Note that you should do the "looping" here with tail recursion.

Since this is group work, the group produces a common solution and one group member submits the entire solution on behalf of all the group members. Put an erlang comment in your module source files naming all the group members, or naming the solo person doing the work. Something like this directive at the top of each module source file:

    -team("bob smith, jane doe, kim kinney").
 or
    % team: bob smith, jane doe, kim kinney
Identify the coder(s) even if you are a solo "team".

Make two modules... named "p1" and "p2" . Put your module source files into one zip file, include a README file for any comments you might want to note (as well as put your group member names in that README file), and in Canvas, submit this single zip file.


Assignment 2: Java Threads

Team work
Due: Sunday 9/8 11:59pm

With your team members, review java threads (from COMP 301 at the end) and try the Java thread programs given in the class calendar (zip file).

Then write a Java threads-based solution to the Dining Philosophers problem. Make sure your solution does not deadlock, and does not starve any philosopher.




Assignment 1: OO Problems and Issues

Solo work
Due: Wed 8/28 9pm

In canvas you will see the problem defined... researching and writing a short paper on the criticisms and issues with Objects and OO programming.




Assignment 0: Teams

Due: ASAP, but by Sun. 8/25 9:00pm in class email

You are allowed to work together in teams of size 1, 2, or 3 this semester.

  1. So get together with others and form teams.

  2. Send me email (to the class account) telling me the names of the students on your team. One email per team, all names of team members in that one email.

  3. If you want to be a team of 1, send me email as well saying you are solo (so I can be sure I have heard from the entire class).

  4. If you wish to be teamed and have no names to pair with, send me an email saying you wish to be teamed and I will pair you (or triple you) with others wanting the same.