Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Class Notes for The Zen of Threads | Design of Large Programs | CS 351L, Study notes of Computer Science

Material Type: Notes; Professor: Lane; Class: Design of Large Programs; Subject: Computer Science; University: University of New Mexico; Term: Fall 2006;

Typology: Study notes

Pre 2010

Uploaded on 07/23/2009

koofers-user-pja-1
koofers-user-pja-1 🇺🇸

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The Zen of Threads
When you can snatch the lock from the object,
grasshopper, then you are ready to spawn the thread...
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Class Notes for The Zen of Threads | Design of Large Programs | CS 351L and more Study notes Computer Science in PDF only on Docsity!

The Zen of Threads

When you can snatch the lock from the object, grasshopper, then you are ready to spawn the thread...

Time keeps on rollin’...

Last time:

Quiz 2

P3 assigned

This time:

Threads vs. procs

Synchronization

Fail fast principle (maybe)

Three modes of execution

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

Multi-process model

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)

Multi-process model

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

Multi-process model

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

Inter-process comm.

pipe.write() pipe.read()

Multi-thread model

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!

The Multi-Thread Model

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

Thread communication

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