CS 350 Homework 3

1 Instructions

  • The first two questions have to be submitted by the same group which submitted HW2. The remaining questions must be done individually.

2 Questions - Declative concurrent model

  1. Extend your code in Homework 2 to support the following semantic statement:

    (thread <s> end, E)
    

    This requires you to extend the stack to a semantic multistack. Follow the semantics that we have covered in the class. [25 points]

  2. Implement a round-robin thread scheduler, which goes over all the current stacks and executes a stack if the top statement is not suspended. [25 points]
  3. Write a function {WaitBoth X1 X2} which waits until both X1 and X2 are determined.

    Using the above function, write a function {Thread P1 P2} which simulates threading with a parent-children relationship: the main thread of the function runs the procedures P1 and P2 in separate threads. The main thread then waits for the two child threads to terminate, and only then it itself terminates.

  4. A programmer can create a trigger in an eager language, if instead of a value V, at any stage of a computation, if we return fun {$} V end.

    The caller now should evaluate the function when the value is really required. This technique is called thunking.

    Using this idea, write an eager Oz function to return the merged sorted list of two given sorted lists of numbers. [15 points]

3 Questions : Message Passing Model

  1. a) The function {IsDet X} returns true when X is determined, and false otherwise, without suspending. Show that adding IsDet will cause the model to be non-declarative.

    (Hint: Construct a threaded program using IsDet where different interleavings succeed with logical inequivalent stores. Why does this suffice to show that the model is not declarative?) [10 points]

  2. [Server] Using port objects, create a port which takes a message-processing procedure P as an argument (See NewPort2 in the course notes, and adapt the code.) Ensure that the port object creates a non-terminating thread to process the individual messages it later receives, using P. [10 points]
  3. [Client] Create a client which creates a client port, which upon receving any message, displays it in the Browser.

    It should also create a server port as per the above question. The message-processing procedure should be a function which takes a string, and does the following.

    • It reverses the string
    • It sends the reversed string to the client port. [15 points]

Author: Satyadev Nandakumar

Created: 2019-10-19 Sat 07:31

Validate