

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


CS 326 Operating Systems Greg Benson 1
2
OS kernel
memory blocks
understanding to avoid common mistakes
3
instance to another struct instance via a pointer in the struct:
(also more...) struct node { struct node *next; int x; int y; } struct node *head; next x y next x y
x y Head 4
list_entry() macro
ordering
#define offsetof(TYPE, MEMBER)
(size_t) &((TYPE *) 0)->MEMBER) struct point { int x; int y; int z; char c; float o; }; 0: x (4 byte int) 4: y (4 byte int) 8: z (4 byte int) 12: c (1 byte char) 13: 3 byte padding 16: o (4 byte float) 6
Project 0 ! Addressed ordered first-fit ! Coalescing free blocks Free block Used block Free list User Objects Continuous Memory Region 7 Process Definition Review ! A program in execution ! An instance of a program running on a computer ! A process has ! User-level state: memory + register values ! Memory: stack, heap, code ! Kernel-level state: stack, process info, memory maps, file descriptors, network connections... 8 Threads ! A thread is “smaller than” a process ! A thread represents an execution sequence: ! registers + stack ! Threads run in the context of a process ! A process provides memory and kernel state ! Alternate process definition: ! n threads + shared resources (heap, global vars, kernel state) 9!^ Note: each thread needs it’s own stack Scheduling ! An OS kernel schedules threads ! Basic idea: ! Run a thread for a fixed period of time or until it blocks (i.e., wait for date from network) ! Pick a different thread and switch to it ! If no threads ready to run, then twiddle (idle) 10 Using Threads ! Basic ideas ! Thread creation ! Create a new execution sequence ! Need: a new stack and a start function ! Thread interaction ! Need to^ synchronize^ access to shared resources (e.g., global and heap memory) 11 Pthreads ! POSIX Threads ! A standard API available on Linux, Mac OS X, and Windows (not common) ! We will look two sets of functions ! pthread_create() and pthread_join() ! pthread_mutex_lock() and pthread_mutex_unlock() 12