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
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]
- 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]
Write a function
{WaitBoth X1 X2}
which waits until bothX1
andX2
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 proceduresP1
andP2
in separate threads. The main thread then waits for the two child threads to terminate, and only then it itself terminates.A programmer can create a trigger in an eager language, if instead of a value
V
, at any stage of a computation, if we returnfun {$} 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
a) The function
{IsDet X}
returns true whenX
is determined, and false otherwise, without suspending. Show that addingIsDet
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]- [Server] Using port objects, create a port which takes a
message-processing procedure
P
as an argument (SeeNewPort2
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, usingP
. [10 points] [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]