On this page:
16.1 Message Passing Concurrency
16.2 Problem 1
16.3 Problem 2
16.4 Problem 3
16.5 Problem 4
16.6 Problem 5
16.7 Problem 6
16.8 Problem 7
16.9 Problem 8
8.11

16 Homework 10B

Due:

Thursday, 3/21 at 9PM

This assignment is SOLO, and entirely AUTOGRADED.

What to Download:

hw10b.rkt

Please start with this file, filling in where appropriate, and submit your homework to the HW10B assignment on Gradescope. This page has additional information, and allows us to format things nicely.

16.1 Message Passing Concurrency

In this HW, you will design a program with three processes, "a", "b", and "c".

The program will start by having process "a" send a message "hello" to process "b".

Whenever process "b" receives message "hello" from process "a", it should send message "hello" to process "c".

Whenever process "c" receives message "hello" from process "b", it should send message "got it" to process "a", unless it has already received 4 "hello" messages from process "b", in which case it should do nothing.

Whenever process "a" receives message "got it" from process "c", it should send message "hello" to process "b".

16.2 Problem 1

Processes update their own state in response to messages so when designing concurrent programs, the first task is to think about the state of each process. In this problem, your task is to define the state for process "a".

 (define-contract AState ...)

16.3 Problem 2

Next, define handlers for the "a" process: the handler that is called once at the beginning of the program, to initialize the processes, and the handler that is called every time process "a" receives a message. Write tests for both.

 (: a-start (-> (List String) (Action AState))) 
 (define (a-start others) 
   ...) 
  
 (test-suite 
  "a-start" 
  ...) 
  
 (: a-receive (-> AState (ReceivePacket String) (Action AState))) 
 (define (a-receive st pkt) 
   ...) 
  
 (test-suite 
  "a-receive" 
  ...)

16.4 Problem 3

Now, repeat Problem 1 with process "b":

 (define-contract BState ...)

16.5 Problem 4

And, repeat Problem 2 with process "b":

 (define-contract BState ...)

16.6 Problem 5

Now, repeat Problem 1 with process "c":

 (define-contract CState ...)

16.7 Problem 6

And, repeat Problem 2 with process "c":

 (: c-start (-> (List String) (Action CState))) 
 (define (c-start others) 
   ...) 
  
 (test-suite 
  "c-start" 
  ...) 
  
 (: c-receive (-> CState (ReceivePacket String) (Action CState))) 
 (define (c-receive st pkt) 
   ...) 
  
 (test-suite 
  "c-receive" 
  ...)

16.8 Problem 7

Now that you have the state and handlers for all the processes, you can define them using process:

 (define a-process ...) 
 (define b-process ...) 
 (define c-process ...)

16.9 Problem 8

And, for your last task, define two zero-argument functions: main and main-debug, that run the program using start and start-debug respectively. You can use first as the scheduler for both of them.