








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Material Type: Notes; Professor: Lane; Class: Design of Large Programs; Subject: Computer Science; University: University of New Mexico; Term: Fall 2006;
Typology: Study notes
1 / 14
This page cannot be seen from the preview
Don't miss anything!
When you can snatch the lock from the object, grasshopper, then you are ready to spawn the thread...
Last time:
Quiz 2
P3 assigned
This time:
Threads vs. procs
Synchronization
Fail fast principle (maybe)
Threads
Called “light weight processes”
Efficient: >1 user, no blocking, efficient use of resources
Data sharing: shared memory
Multiple threads read/write same memory space
Synchronization: very tricky
Process (UNIX sense):
Separate program, running in own memory space, independent of all other programs/ processes on computer
Each process has own copy of:
Program instructions/code (“text” segment)
Program counter (PC)
Registers
Method local variables (stack)
Object local variables (heap)
Memory proc 0 proc 1 proc 2 addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text PC .stack regs: $0,$1,... Obj Obj ObjN .heap
Memory proc 0 proc 1 proc 2 addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text PC .stack regs: $0,$1,... Obj Obj ObjN .heap mult $2,$ cmpi $5, be $5,$ sto $7,$ sub $3,$ jmpi 415 ... .text PC addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text PC .stack regs: $0,$1,... Obj Obj Obj .stack regs: $0,$1,... Obj Obj ObjK Obj .heap .heap
Memory proc 0 proc 1 proc 2 addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text PC .stack regs: $0,$1,... Obj Obj ObjN .heap mult $2,$ cmpi $5, be $5,$ sto $7,$ sub $3,$ jmpi 415 ... .text PC addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text PC .stack regs: $0,$1,... Obj Obj Obj .stack regs: $0,$1,... Obj Obj ObjK Obj .heap .heap
pipe.write() pipe.read()
Threads run within a single process
Each thread has its own
Program counter (PC)
Registers
Method-local variables (stack)
All threads in a single process share:
Program instructions/code (text)
Object local variables/“main memory” (heap)
No kernel/hardware separation! All separation is done by you!
Memory proc 0 addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text Obj Obj ObjN Obj Obj Obj Obj Obj ObjK Obj PC registers^ .stack thread 0 .heap PC registers^ .stack thread 1 PC registers^ .stack thread 2
Memory proc 0 addi $0, bne $3,$4, nop mult $7,$ mflo $ sw $3,$ ... .text Obj Obj ObjN Obj Obj Obj Obj Obj ObjK Obj PC registers^ .stack thread 0 .heap PC registers^ .stack thread 1 PC registers^ .stack thread 2