
Concurrency and Memory-Safe Systems Software Development Lab Overview
Explore the intricacies of modularizing code, establishing namespaces, and struct initialization for safe software development in the CSE 542S course. Learn to create return wrappers and enhance termination behaviors for enhanced system reliability.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
E81 CSE 542S: Concurrency and Memory Safe System Software Development Lab 2 Overview Department of Computer Science & Engineering Chris Gill cdgill@wustl.edu 1
Objective 1: Modularity Organize the code into modules Use directory and file structure along with special mod.rs file to establish namespaces Access other modules via use statements Test with lab 1 files should work as before Then move most of the functions into implementation blocks for struct types Test with lab 1 files should work as before 2 CSE 542S Concurrency and Memory Safe System Software Development
Struct Modularity and Access Declare functions and methods that other modules will use to be public E.g., pub fn grab_trimmed_file_lines... Within functions and methods of a struct implementation, use Self for associated functions and self for methods or fields E.g., Self::add_config(...); E.g., self.players.len(); 3 CSE 542S Concurrency and Memory Safe System Software Development
An Initialization Idiom for Structs Associated new function in impl block Takes no parameters, or only takes parameters whose values are stored directly Initializes fields to have the passed values or to have defaulted values or to be empty Further initialization that could fail (e.g., tries to open a file) is done by methods Those return Result types with which to indicate success or failure accordingly 4 CSE 542S Concurrency and Memory Safe System Software Development
Objective 2: Return Wrapper Inadequate termination behavior currently Termination trait implementation for ExitCode doesn t print out a message with the error value (must use echo $? to see the return value) Termination for Result gives value 1 for any error Can t impl Termination for u8: see BOT p. 270 discussion of Rust s orphan rule across crates Update termination behavior for a new type Wrap u8 value in a struct, implement Termination to print wrapped value + return it as an ExitCode 5 CSE 542S Concurrency and Memory Safe System Software Development
Return Wrapper Design pub struct ReturnWrapper {retval: u8} impl Termination for ReturnWrapper { fn report(self) -> ExitCode {...} } impl ReturnWrapper { pub fn new (r: Result<(), u8>) -> ReturnWrapper {...} } fn main() -> ReturnWrapper {... ReturnWrapper::new(Ok(())) } 6 CSE 542S Concurrency and Memory Safe System Software Development
Objective 3: Stage Management Then add scene fragment progression At each new scene print out its title At scene fragment start, announce entrances in order of first speaking in that fragment; announce exits at end, in reverse order Only announce entrances for characters not already on the stage, only announce exits for characters not in next scene fragment Test completed solution with lab 2 files 7 CSE 542S Concurrency and Memory Safe System Software Development
Ordering Entrances and Exits A play manages its scene fragments In the order they appear in a script file A scene fragment manages its players Use sort to order players by 1st line number Implement PartialEq, Eq, PartialOrd and Ord traits (see BOT Ch.12) for Player struct Watch out for collisions between use statements for std::cmp::Ordering and std::sync::atomic::Ordering 8 CSE 542S Concurrency and Memory Safe System Software Development
Moving Between Scenes & Fragments Polonius. Farewell! [Exit Reynaldo.] [Enter Ophelia.] Hamlet_II_1a Polonius. How now, Ophelia! what's the matter? Hamlet_II_1b [Exit Ophelia.] [Exit Polonius.] Hamlet_II_2a ... Scene II A room in the Castle ... [Enter King.] [Enter Queen.] [Enter Rosencrantz.] [Enter Guildenstern.] 9 CSE 542S Concurrency and Memory Safe System Software Development
Whingeing vs. Failures Still need to tolerate manageable issues Should handle whitespace anywhere, and for lab 2 should do so without complaining Still complain about play lines with either no number or no text (but not blank lines) Fail if script file cannot be opened Capture any non-empty script file line s first token: if not [scene]it s a config file name If can t open that config file, return failure 10 CSE 542S Concurrency and Memory Safe System Software Development
Missing or Duplicate Lines If a line number is missing and there are still lines to be delivered in the play Skip the missing line but if whinge mode is on, complain about the missing line number If two lines have the same number either within a player or between players Deliver them consecutively in the order the program encounters them, and if whinge mode is on complain about the duplication 11 CSE 542S Concurrency and Memory Safe System Software Development
Lab 2 Assignment Please make sure to read and follow the course programming guidelines as you write the code Test your solution thoroughly, with both well formed inputs and with bad formats & values, and with and without whinge mode Make sure that the program prints out the same result value as is given by running echo $? Lab 2 is due by 11:59pm on Friday 11/1/24 Please upload files in Canvas, make sure same person who submitted original resubmits if needed 12 CSE 542S Concurrency and Memory Safe System Software Development