9 Homework 10
This assignment is due Thursday, 3/20 by MIDNIGHT
What to Download:
Submit your completed file to the HW10 assignment on Gradescope.
9.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".
9.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 ...) |
9.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" |
...) |
9.4 Problem 3
Now, repeat Problem 1 with process "b":
(define-contract BState ...) |
9.5 Problem 4
And, repeat Problem 2 with process "b":
(: b-start (-> (List String) (Action BState))) |
(define (b-start others) |
...) |
(test-suite |
"b-start" |
...) |
(: b-receive (-> BState (ReceivePacket String) (Action BState))) |
(define (b-receive st pkt) |
...) |
(test-suite |
"b-receive" |
...) |
9.6 Problem 5
Now, repeat Problem 1 with process "c":
(define-contract CState ...) |
9.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" |
...) |
9.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 ...) |
9.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.
9.10 Memo About PBT
Throughout the last nine weeks, you’ve been learning software specification techniques, and the language LSL that we built specifically to make it easier for you to learn those techniques.
However, none of what we have taught you is exclusive to LSL, and very little is even all that much easier to do in LSL than through combinations of other systems, at least once you learn the tools: there just isn’t a single system that can do all of it nearly as well, and there certainly isn’t one that is as simple to use.
While we’ve covered various techniques, the core of what we have been teaching you involves writing properties down as code and then using random generation to exercise those properties, possibly on hundreds, thousands, or even millions of examplse. This technique, Property Based Testing (PBT), is widely supported, with good libraries written in nearly every programming language.
9.11 Problem 9
In this assignment, we want you to first identify a PBT library in a programming language that you have used outside of CS2800. If all your programming experience is CS2500 & CS2800 and you are not taking CS2510 concurrently (in which case, use Java), look for a Racket PBT library. Often times these libraries have the name "Quickcheck" in their name, after the system, created in 1999, that originated the idea.
9.12 Problem 10
Once you have identified your library, your next task is to write a memo that summarizes its strengths and weaknesses. Both try it out yourself, but also produce annotated examples explaining how the examples work. You may not simply duplicate official or unofficial documentation for the library (that is plagiarism: this must be your own work), though you clearly can read and learn from those.
Produce at least three examples, and at least a few paragraphs describing the library.
The audience for this should be coworkers at a software coop or company where you are working. Imagine you are tasked with explaining how the system works, and assessing its strengths and weaknesses.
9.13 Problem 11
Understanding the technical mechanism of the library is one thing, but why should this be done? Imagine you are writing a separate memo to a manager at the same software coop or company. For this problem, you should write several (>=2) paragraphs justifying why use of this library should be incorporated. What benefits might you gain? What drawbacks do you expect? Are the drawbacks inherent to the approach, or details of the library you identified in Problem 10? Imagine that the manager has access to your more technical explanation from Problem 10, but may not want to read it.