SlideShare una empresa de Scribd logo
1 de 66
Plan for Today
Administrative Things
Communication, Grading, Recording
Learning Rust
How to Share a Processor

1
Human

Human Communication

IRC: quick and dirty
#cs4414: immediate responses
#rust: general Rust questions

Web: rust-class.org
Page-specific (e.g., PS1, Class 1
notes)
General forums

easiest for others to see
Email: evans@virginia.edu
best for longer questions/responses
Use only for things that don’t fit into other channels
Notify me if you asked something on web but didn’t get a response
Anything that you want to keep private
2
Grading
Don’t be stressed!

3
4
cs4414 Grading Form
1

/1

Your program pretty much works!

You will have plenty of ways to distinguish yourself as
outstanding, but by doing something creating and
extraordinary, not by being perfect on some checklist of
minutiae.

5
For Future Problem Sets
Auto-grader
You’ll be able to confirm that your code behaves as
expected before submitting (and can try as many times
as you want)

Demos
All team members will answer questions about design
decisions, concepts, how to extend, etc.

Teammate Ratings
6
Recording Classes

Can’t promise to record everything
Recordings will be (somewhat) edited
Press the button in front of you unless you want to be recorded

7
Questions

8
Rust
Expressions
and Functions
9
Java / C / C++
IfStatement ::=
if (Expression)
StatementTrue
[ else
StatementFalse
]

Rust
IfExpression ::=
if Expression Block
[ else Block ]
Block ::= { [Statement* Expr] }
Expression ::= Block
Statement ::= Expression ;

Simplified: static.rust-lang.org/doc/master/rust.html#if-expressions.
Warning: “(looking for consistency in the manual's grammar is bad:
it's entirely wrong in many places.)”
10
Quiz

IfExpression ::=
if Expression Block
[ else Block ]

Block ::= { [Statement* Expr] }
Expression ::= Block

fn max(a: int, b: int) -> int {
if { } { a } else { b }
a) Syntax Error
}
b) Type Error
c) Run-time Error

11
fn max(a: int, b: int) -> int {
if { } { a } else { b }
}

IfExpression ::=
if Expression Block
[ else Block ]

Block ::= { [Statement* Expr] }
Expression ::= Block

$ rustc block.rs
block.rs:2:7: 2:10 error: mismatched types: expected `bool` but
found `()` (expected bool but found ())
block.rs:2 if { } {
If you get bad error messages
^~~

from rustc,report them to Kiet!
12
(Trick) Quiz

IfExpression ::=
if Expression Block
[ else Block ]

Block ::= { [Statement* Expr] }
Expression ::= Block

fn max(a: int, b: int) -> int {
if { let x = 4414; x = x + a; x > b + 4414 } { a }
else { b }
a) Syntax Error
}
b) Type Error
c) Run-time Error

13
fn max(a: int, b: int) -> int {
if { let x = 4414; x = x + a; x > b + 4414 } { a }
else { b }
}
$ rustc block.rs
block.rs:2:23: 2:24 error: re-assignment of immutable variable `x`
block.rs:2 if { let x = 4414; x = x + a; x > b + 4414 } {
^
“Variables” are invariable…unless declared with mut.
14
fn max(a: int, b: int) -> int {
if { let mut x = 4414; x = x + a; x > b + 4414 } { a }
else { b }
}
$ rust run block.rs
Max: 5

15
Quiz
fn max(a: int, b: int) -> int {
if a > b { a } else { b; }
}

IfExpression ::=
if Expression Block
[ else Block ]

Block ::= { [Statement* Expr] }
Expression ::= Block
Statement ::= Expression ;

a) Syntax Error
b) Type Error
c) Run-time Error
16
fn max(a: int, b: int) -> int {
if a > b { a } else { b; }
The semi-colon makes it a statement – no value
}
block.rs:2:24: 2:30 error: mismatched types: expected `int`
but found `()` (expected int but found ())
block.rs:2 if a > b { a } else { b; }
^~~~~~
17
Higher-Order Functions
Java
Java 8 (March 2014)

Scheme

Rust
| <parameters> | Block
proc(<parameters>) Block

(define (make-adder a)
(lambda (n)
(+ a n)))
18
Define a function, make_adder, that takes an
int as input and returns a function that takes
and int and returns the sum of the original and
input int.
let increment = make_adder(1);
increment(3) => 4

19
fn make_adder(a: int) -> (fn(int) -> int) {
fn(b: int) { a + b }
}
fn main() {
let increment = make_adder(1);
println!("result: {:x}", increment(2));
}

Limitation: we can only use increment once!
20
Define a function, ntimes, that takes as inputs a
function f (int -> int) and an integer n, and
returns a function that applies f n-times.
fn double(a: int) -> int { a * 2 }
fn main() {
let quadruple = ntimes(double, 2);
println(fmt!("quad: %?", quadruple(2)));
}
21
fn double(a: int) -> int { a * 2 }

fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int {
proc(x: int) {
match times { 0 => { x }
_ => { ntimes(f, times - 1)(f(x))}
}
}}
fn main() {
let quadruple = ntimes(double, 2);
println!("quad: {:d}", quadruple(2));
}
22
fn double(a: int) -> int { a * 2 }

fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int {
proc(x: int) {
match times { 0 => { x } bash-3.2$ rustc ntimes.rs
bash-3.2$ ./ntimes
_ => { ntimes(f, times - 1)(f(x))}
}
Segmentation fault: 11
}}
Note: {
fn main() when a C/C++ program gives a “Segmentation
fault”, 99.9999% of the time it is
let quadruple = ntimes(double, 2);the programmers “fault”.
When a Rust {:d}", quadruple(2));
println!("quad:program (that doesn’t use unsafe)
} does, 100% of the time it is Rust’s fault.
23
24
25
Rust or Bust?
Rust

 Immature, Unstable
 Poorly documented
 Few open source projects
(except Servo)
 Not in high employer
demand
 No other courses
28 January 2014

Bust (C)

 Mature, Stable
 Hundreds of books, etc.
 Lots of open source
projects (incl. Linux)
 Popular for interview
questions
 Nearly all OS courses

University of Virginia cs4414

26
Rust

Bust (C)

 Benefits from 30 years of
language research
 Chance to influence a
new, exciting, fastevolving language
 Really cool features for
memory management
and concurrency
 FUN!

 Suffers from maintaining
backwards compatibility
 C++0x standard process
began in 1998, released in
2011, over 40 meetings
 Lots of complexity, but
not designed for safety
 Boring, Annoying

27
But what about the
Lack of Documentation?!

28
“Baby”
programmer
(cs1xxx)

29
Give up in
disgust!
30
cs4414 Student

“Professional
Amateur
Programmer”
31
Solving Programming Mysteries
1.
2.
3.
4.

DuckDuckGo (or Google) is your friend!
stackoverflow [rust]
Experiment!
If you figure something
Ask for help:
useful out that is not well

– IRC
– rust-class.org

documented, document it:
course forum
comment, “blog” post
32
Instead of whinging about how
bad the Rust documentation for
strings is….

28 January 2014

University of Virginia cs4414

33
Be happy! You can be
the first to write one!

28 January 2014

University of Virginia cs4414

34
Be happy! You can be
the first to write one!

28 January 2014

Note: last semester’s students
had much less
documentation, and an even
more buggy compiler, but still
survived! (And some did
contribute to writing the tutorials
and improving the compiler you
University of Virginia cs4414
35
are using now.)
How can several programs share
a processor?

36
Batch Processing

Recap
Last Class

Program

Program A
Program B

Multiprogramming

A
B

A

Program C

C
37
Kinds of Processor-Sharing
Multiprogramming
User program runs until it gets stuck, then supervisor runs.
Non-preemptive multi-tasking
User program runs until it decides to let the supervisor run.

Preemptive multi-tasking
User program runs until the (approximately) supervisor
decides to let another program run.
38
Non-preemptive

Preemptive

39
Which have preemptive
multitasking?

MULTICS (1969)

UNIX (1975)

Microsoft
Windows 2.1x
1988
PowerMac G5
(Mac OS 9)
2006
MacBook Air
(Mac OS X)
2011
40
Which have preemptive
multitasking?

MULTICS (1969)

UNIX (1975)

Microsoft
Windows 2.1x
1988
PowerMac G5
(Mac OS 9)
2006
MacBook Air
(Mac OS X)
2011
41
How could I prove it?
Mac OS X
42
42
One-line “Proof”

43
Which are result from preemptive multitasking?
A.
B.
C.
D.

A computer running Mac OS X crashes less than one
running Mac OS 9
A computer running Mac OS X needs fewer hard
reboots than one running Mac OS 9
When you watch your favorite Eminem video for the
50th time, the video still (occasionally) jitters
Your zhttpto server can handle more than one request
at a time
44
Mac OS 9.2.2
5 Dec 2001

Mac OS X (Cheetah)
24 March 2001

How did Apple add preemptive multitasking to Mac OS?
45
(The answer is
probably not in this
movie.)
http://www.youtube.com/watch?
v=YsWBJ_usRck&t=2m18s
46
“Once you make them
talk, they won’t be
inanimate anymore.”
Steve Jobs (as quoted by
Sorkin earlier in interview)
47
https://upload.wikimedia.org/wikipedia/commons/7/77/Unix_history-simple.svg

48
49
50
51
Sir Tim Berners Lee
finishing PS1 24
years early!
52
MULTICS

Code (carries license)

“Ideas” (no
license, possible patent
lawsuits)

Unix

BSD

NextStep

Minix

FreeBSD

Linux

Mac OS X
Android
iOS

53
How can
preemptive multitasking
even be possible?!?
Preemptive multi-tasking
User program X runs until the supervisor
decides to let another program run.
54
Preemptive (?) Multitasking
Program A

A

Program B

B

Program C

A

Supervisor
Supervisor

Supervisor
A
55
56
57
Interrupts
How frequently
should the
supervisor’s alarm
clock (“kernel timer
interrupt”) go off to
check on the
workers?
58
My MacBook (Ubuntu)
timer.c is a 50-line C program from
http://www.advenage.com/topics/linux-timer-interrupt-frequency.php (link on notes)

bash-3.2$ uname -a
Darwin Davids-MacBook-Air-2.local 11.4.2 Darwin Kernel
Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu1699.32.7~1/RELEASE_X86_64 x86_64
bash-3.2$ gcc timer.c ; ./a.out
kernel timer interrupt frequency is approx. 4016 Hz or higher

Rust version by Wil Thomason
59
Timer Interrupts
Super
visor

A

set alarm clock
switch to program A

Supervisor

B

Supervisor

set alarm clock
switch to program B

What makes the alarm clock ring?
60
Who interrupts the supervisor?

61
The supervisor’s supervisor!

a.k.a. Hypervisor
62
Support for hypervisor added
to Intel x86 in 2005 (VT-x)
63
More general (quite similar)
idea in MULTICS (but with
8-levels of supervision in
hardware by 1975)
64
Charge
Tutorial Part 3 and Problem Set 2 will be
posted later today
PS2 is due February 9
Longer and more challenging than PS1, don’t wait
to get started

Read the Process API and Direct Execution
sections of the OSTEP book
65

Más contenido relacionado

La actualidad más candente

Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)
David Evans
 
110864103 adventures-in-bug-hunting
110864103 adventures-in-bug-hunting110864103 adventures-in-bug-hunting
110864103 adventures-in-bug-hunting
bob dobbs
 
Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++
Shuo Chen
 

La actualidad más candente (20)

Gash Has No Privileges
Gash Has No PrivilegesGash Has No Privileges
Gash Has No Privileges
 
Synchronization
SynchronizationSynchronization
Synchronization
 
What the &~#@&lt;!? (Pointers in Rust)
What the &~#@&lt;!? (Pointers in Rust)What the &~#@&lt;!? (Pointers in Rust)
What the &~#@&lt;!? (Pointers in Rust)
 
Scheduling in Linux and Web Servers
Scheduling in Linux and Web ServersScheduling in Linux and Web Servers
Scheduling in Linux and Web Servers
 
Kernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easyKernel Recipes 2019 - Formal modeling made easy
Kernel Recipes 2019 - Formal modeling made easy
 
Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)Putting a Fork in Fork (Linux Process and Memory Management)
Putting a Fork in Fork (Linux Process and Memory Management)
 
Scheduling
SchedulingScheduling
Scheduling
 
Virtual Memory (Making a Process)
Virtual Memory (Making a Process)Virtual Memory (Making a Process)
Virtual Memory (Making a Process)
 
Making a Process
Making a ProcessMaking a Process
Making a Process
 
Crossing into Kernel Space
Crossing into Kernel SpaceCrossing into Kernel Space
Crossing into Kernel Space
 
Where destructors meet threads
Where destructors meet threadsWhere destructors meet threads
Where destructors meet threads
 
Coding for multiple cores
Coding for multiple coresCoding for multiple cores
Coding for multiple cores
 
java memory management & gc
java memory management & gcjava memory management & gc
java memory management & gc
 
Lockless Programming GDC 09
Lockless Programming GDC 09Lockless Programming GDC 09
Lockless Programming GDC 09
 
110864103 adventures-in-bug-hunting
110864103 adventures-in-bug-hunting110864103 adventures-in-bug-hunting
110864103 adventures-in-bug-hunting
 
Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++
 
Is your profiler speaking the same language as you? -- Docklands JUG
Is your profiler speaking the same language as you? -- Docklands JUGIs your profiler speaking the same language as you? -- Docklands JUG
Is your profiler speaking the same language as you? -- Docklands JUG
 
Booklet
BookletBooklet
Booklet
 
DevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The CoversDevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The Covers
 
john-devkit: 100 типов хешей спустя / john-devkit: 100 Hash Types Later
john-devkit: 100 типов хешей спустя / john-devkit: 100 Hash Types Laterjohn-devkit: 100 типов хешей спустя / john-devkit: 100 Hash Types Later
john-devkit: 100 типов хешей спустя / john-devkit: 100 Hash Types Later
 

Similar a Once Upon a Process

ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
Amos Wenger
 
JavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfJavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdf
Sathwika7
 
A Replay Approach to Software Validation
A Replay Approach to Software ValidationA Replay Approach to Software Validation
A Replay Approach to Software Validation
James Pascoe
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
fntsofttech
 

Similar a Once Upon a Process (20)

Devry CIS 355A Full Course Latest
Devry CIS 355A Full Course LatestDevry CIS 355A Full Course Latest
Devry CIS 355A Full Course Latest
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
ooc - A hybrid language experiment
ooc - A hybrid language experimentooc - A hybrid language experiment
ooc - A hybrid language experiment
 
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-StudioArcheology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
Archeology for Entertainment, or Checking Microsoft Word 1.1a with PVS-Studio
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
JavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdfJavaProgrammingForBeginners-Presentation.pdf
JavaProgrammingForBeginners-Presentation.pdf
 
Computer ScienceTechnical quiz
Computer ScienceTechnical quizComputer ScienceTechnical quiz
Computer ScienceTechnical quiz
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications development
 
A Replay Approach to Software Validation
A Replay Approach to Software ValidationA Replay Approach to Software Validation
A Replay Approach to Software Validation
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Software Testing for Data Scientists
Software Testing for Data ScientistsSoftware Testing for Data Scientists
Software Testing for Data Scientists
 
Testing in Python: doctest and unittest
Testing in Python: doctest and unittestTesting in Python: doctest and unittest
Testing in Python: doctest and unittest
 
ODU ACM Python & Memento Presentation
ODU ACM Python & Memento PresentationODU ACM Python & Memento Presentation
ODU ACM Python & Memento Presentation
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)Testing in Python: doctest and unittest (Updated)
Testing in Python: doctest and unittest (Updated)
 
Wtf per lineofcode
Wtf per lineofcodeWtf per lineofcode
Wtf per lineofcode
 
C Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer CentreC Programming Training in Ambala ! Batra Computer Centre
C Programming Training in Ambala ! Batra Computer Centre
 
PythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummiesPythonBrasil[8] - CPython for dummies
PythonBrasil[8] - CPython for dummies
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageable
 

Más de David Evans

Más de David Evans (20)

Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!Cryptocurrency Jeopardy!
Cryptocurrency Jeopardy!
 
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for CypherpunksTrick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
Trick or Treat?: Bitcoin for Non-Believers, Cryptocurrencies for Cypherpunks
 
Hidden Services, Zero Knowledge
Hidden Services, Zero KnowledgeHidden Services, Zero Knowledge
Hidden Services, Zero Knowledge
 
Anonymity in Bitcoin
Anonymity in BitcoinAnonymity in Bitcoin
Anonymity in Bitcoin
 
Midterm Confirmations
Midterm ConfirmationsMidterm Confirmations
Midterm Confirmations
 
Scripting Transactions
Scripting TransactionsScripting Transactions
Scripting Transactions
 
How to Live in Paradise
How to Live in ParadiseHow to Live in Paradise
How to Live in Paradise
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Mining Economics
Mining EconomicsMining Economics
Mining Economics
 
Mining
MiningMining
Mining
 
The Blockchain
The BlockchainThe Blockchain
The Blockchain
 
Becoming More Paranoid
Becoming More ParanoidBecoming More Paranoid
Becoming More Paranoid
 
Asymmetric Key Signatures
Asymmetric Key SignaturesAsymmetric Key Signatures
Asymmetric Key Signatures
 
Introduction to Cryptography
Introduction to CryptographyIntroduction to Cryptography
Introduction to Cryptography
 
Class 1: What is Money?
Class 1: What is Money?Class 1: What is Money?
Class 1: What is Money?
 
Multi-Party Computation for the Masses
Multi-Party Computation for the MassesMulti-Party Computation for the Masses
Multi-Party Computation for the Masses
 
Proof of Reserve
Proof of ReserveProof of Reserve
Proof of Reserve
 
Silk Road
Silk RoadSilk Road
Silk Road
 
Blooming Sidechains!
Blooming Sidechains!Blooming Sidechains!
Blooming Sidechains!
 
Useful Proofs of Work, Permacoin
Useful Proofs of Work, PermacoinUseful Proofs of Work, Permacoin
Useful Proofs of Work, Permacoin
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

Once Upon a Process

  • 1.
  • 2. Plan for Today Administrative Things Communication, Grading, Recording Learning Rust How to Share a Processor 1
  • 3. Human Human Communication IRC: quick and dirty #cs4414: immediate responses #rust: general Rust questions Web: rust-class.org Page-specific (e.g., PS1, Class 1 notes) General forums easiest for others to see Email: evans@virginia.edu best for longer questions/responses Use only for things that don’t fit into other channels Notify me if you asked something on web but didn’t get a response Anything that you want to keep private 2
  • 5. 4
  • 6. cs4414 Grading Form 1 /1 Your program pretty much works! You will have plenty of ways to distinguish yourself as outstanding, but by doing something creating and extraordinary, not by being perfect on some checklist of minutiae. 5
  • 7. For Future Problem Sets Auto-grader You’ll be able to confirm that your code behaves as expected before submitting (and can try as many times as you want) Demos All team members will answer questions about design decisions, concepts, how to extend, etc. Teammate Ratings 6
  • 8. Recording Classes Can’t promise to record everything Recordings will be (somewhat) edited Press the button in front of you unless you want to be recorded 7
  • 11. Java / C / C++ IfStatement ::= if (Expression) StatementTrue [ else StatementFalse ] Rust IfExpression ::= if Expression Block [ else Block ] Block ::= { [Statement* Expr] } Expression ::= Block Statement ::= Expression ; Simplified: static.rust-lang.org/doc/master/rust.html#if-expressions. Warning: “(looking for consistency in the manual's grammar is bad: it's entirely wrong in many places.)” 10
  • 12. Quiz IfExpression ::= if Expression Block [ else Block ] Block ::= { [Statement* Expr] } Expression ::= Block fn max(a: int, b: int) -> int { if { } { a } else { b } a) Syntax Error } b) Type Error c) Run-time Error 11
  • 13. fn max(a: int, b: int) -> int { if { } { a } else { b } } IfExpression ::= if Expression Block [ else Block ] Block ::= { [Statement* Expr] } Expression ::= Block $ rustc block.rs block.rs:2:7: 2:10 error: mismatched types: expected `bool` but found `()` (expected bool but found ()) block.rs:2 if { } { If you get bad error messages ^~~ from rustc,report them to Kiet! 12
  • 14. (Trick) Quiz IfExpression ::= if Expression Block [ else Block ] Block ::= { [Statement* Expr] } Expression ::= Block fn max(a: int, b: int) -> int { if { let x = 4414; x = x + a; x > b + 4414 } { a } else { b } a) Syntax Error } b) Type Error c) Run-time Error 13
  • 15. fn max(a: int, b: int) -> int { if { let x = 4414; x = x + a; x > b + 4414 } { a } else { b } } $ rustc block.rs block.rs:2:23: 2:24 error: re-assignment of immutable variable `x` block.rs:2 if { let x = 4414; x = x + a; x > b + 4414 } { ^ “Variables” are invariable…unless declared with mut. 14
  • 16. fn max(a: int, b: int) -> int { if { let mut x = 4414; x = x + a; x > b + 4414 } { a } else { b } } $ rust run block.rs Max: 5 15
  • 17. Quiz fn max(a: int, b: int) -> int { if a > b { a } else { b; } } IfExpression ::= if Expression Block [ else Block ] Block ::= { [Statement* Expr] } Expression ::= Block Statement ::= Expression ; a) Syntax Error b) Type Error c) Run-time Error 16
  • 18. fn max(a: int, b: int) -> int { if a > b { a } else { b; } The semi-colon makes it a statement – no value } block.rs:2:24: 2:30 error: mismatched types: expected `int` but found `()` (expected int but found ()) block.rs:2 if a > b { a } else { b; } ^~~~~~ 17
  • 19. Higher-Order Functions Java Java 8 (March 2014) Scheme Rust | <parameters> | Block proc(<parameters>) Block (define (make-adder a) (lambda (n) (+ a n))) 18
  • 20. Define a function, make_adder, that takes an int as input and returns a function that takes and int and returns the sum of the original and input int. let increment = make_adder(1); increment(3) => 4 19
  • 21. fn make_adder(a: int) -> (fn(int) -> int) { fn(b: int) { a + b } } fn main() { let increment = make_adder(1); println!("result: {:x}", increment(2)); } Limitation: we can only use increment once! 20
  • 22. Define a function, ntimes, that takes as inputs a function f (int -> int) and an integer n, and returns a function that applies f n-times. fn double(a: int) -> int { a * 2 } fn main() { let quadruple = ntimes(double, 2); println(fmt!("quad: %?", quadruple(2))); } 21
  • 23. fn double(a: int) -> int { a * 2 } fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int { proc(x: int) { match times { 0 => { x } _ => { ntimes(f, times - 1)(f(x))} } }} fn main() { let quadruple = ntimes(double, 2); println!("quad: {:d}", quadruple(2)); } 22
  • 24. fn double(a: int) -> int { a * 2 } fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int { proc(x: int) { match times { 0 => { x } bash-3.2$ rustc ntimes.rs bash-3.2$ ./ntimes _ => { ntimes(f, times - 1)(f(x))} } Segmentation fault: 11 }} Note: { fn main() when a C/C++ program gives a “Segmentation fault”, 99.9999% of the time it is let quadruple = ntimes(double, 2);the programmers “fault”. When a Rust {:d}", quadruple(2)); println!("quad:program (that doesn’t use unsafe) } does, 100% of the time it is Rust’s fault. 23
  • 25. 24
  • 26. 25
  • 27. Rust or Bust? Rust  Immature, Unstable  Poorly documented  Few open source projects (except Servo)  Not in high employer demand  No other courses 28 January 2014 Bust (C)  Mature, Stable  Hundreds of books, etc.  Lots of open source projects (incl. Linux)  Popular for interview questions  Nearly all OS courses University of Virginia cs4414 26
  • 28. Rust Bust (C)  Benefits from 30 years of language research  Chance to influence a new, exciting, fastevolving language  Really cool features for memory management and concurrency  FUN!  Suffers from maintaining backwards compatibility  C++0x standard process began in 1998, released in 2011, over 40 meetings  Lots of complexity, but not designed for safety  Boring, Annoying 27
  • 29. But what about the Lack of Documentation?! 28
  • 33. Solving Programming Mysteries 1. 2. 3. 4. DuckDuckGo (or Google) is your friend! stackoverflow [rust] Experiment! If you figure something Ask for help: useful out that is not well – IRC – rust-class.org documented, document it: course forum comment, “blog” post 32
  • 34. Instead of whinging about how bad the Rust documentation for strings is…. 28 January 2014 University of Virginia cs4414 33
  • 35. Be happy! You can be the first to write one! 28 January 2014 University of Virginia cs4414 34
  • 36. Be happy! You can be the first to write one! 28 January 2014 Note: last semester’s students had much less documentation, and an even more buggy compiler, but still survived! (And some did contribute to writing the tutorials and improving the compiler you University of Virginia cs4414 35 are using now.)
  • 37. How can several programs share a processor? 36
  • 38. Batch Processing Recap Last Class Program Program A Program B Multiprogramming A B A Program C C 37
  • 39. Kinds of Processor-Sharing Multiprogramming User program runs until it gets stuck, then supervisor runs. Non-preemptive multi-tasking User program runs until it decides to let the supervisor run. Preemptive multi-tasking User program runs until the (approximately) supervisor decides to let another program run. 38
  • 41. Which have preemptive multitasking? MULTICS (1969) UNIX (1975) Microsoft Windows 2.1x 1988 PowerMac G5 (Mac OS 9) 2006 MacBook Air (Mac OS X) 2011 40
  • 42. Which have preemptive multitasking? MULTICS (1969) UNIX (1975) Microsoft Windows 2.1x 1988 PowerMac G5 (Mac OS 9) 2006 MacBook Air (Mac OS X) 2011 41
  • 43. How could I prove it? Mac OS X 42 42
  • 45. Which are result from preemptive multitasking? A. B. C. D. A computer running Mac OS X crashes less than one running Mac OS 9 A computer running Mac OS X needs fewer hard reboots than one running Mac OS 9 When you watch your favorite Eminem video for the 50th time, the video still (occasionally) jitters Your zhttpto server can handle more than one request at a time 44
  • 46. Mac OS 9.2.2 5 Dec 2001 Mac OS X (Cheetah) 24 March 2001 How did Apple add preemptive multitasking to Mac OS? 45
  • 47. (The answer is probably not in this movie.) http://www.youtube.com/watch? v=YsWBJ_usRck&t=2m18s 46
  • 48. “Once you make them talk, they won’t be inanimate anymore.” Steve Jobs (as quoted by Sorkin earlier in interview) 47
  • 50. 49
  • 51. 50
  • 52. 51
  • 53. Sir Tim Berners Lee finishing PS1 24 years early! 52
  • 54. MULTICS Code (carries license) “Ideas” (no license, possible patent lawsuits) Unix BSD NextStep Minix FreeBSD Linux Mac OS X Android iOS 53
  • 55. How can preemptive multitasking even be possible?!? Preemptive multi-tasking User program X runs until the supervisor decides to let another program run. 54
  • 56. Preemptive (?) Multitasking Program A A Program B B Program C A Supervisor Supervisor Supervisor A 55
  • 57. 56
  • 58. 57
  • 59. Interrupts How frequently should the supervisor’s alarm clock (“kernel timer interrupt”) go off to check on the workers? 58
  • 60. My MacBook (Ubuntu) timer.c is a 50-line C program from http://www.advenage.com/topics/linux-timer-interrupt-frequency.php (link on notes) bash-3.2$ uname -a Darwin Davids-MacBook-Air-2.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu1699.32.7~1/RELEASE_X86_64 x86_64 bash-3.2$ gcc timer.c ; ./a.out kernel timer interrupt frequency is approx. 4016 Hz or higher Rust version by Wil Thomason 59
  • 61. Timer Interrupts Super visor A set alarm clock switch to program A Supervisor B Supervisor set alarm clock switch to program B What makes the alarm clock ring? 60
  • 62. Who interrupts the supervisor? 61
  • 64. Support for hypervisor added to Intel x86 in 2005 (VT-x) 63
  • 65. More general (quite similar) idea in MULTICS (but with 8-levels of supervision in hardware by 1975) 64
  • 66. Charge Tutorial Part 3 and Problem Set 2 will be posted later today PS2 is due February 9 Longer and more challenging than PS1, don’t wait to get started Read the Process API and Direct Execution sections of the OSTEP book 65