Virtual memory, parallel programming Jakub Yaghob Computer skills Virtual memory, parallel programming Jakub Yaghob
Process Process Program executed by OS Code, data, current activity Private address space
Physical Address Space Virtual memory Process security Work with more memory than available Virtual Address Space Physical Address Space Address Translation
Virtual memory – paging VAS/PAS divided to the blocks of the same size – pages/frames Translation converts a page number to a frame number Translation may not exist – page miss Present bit Page tables One level Multiple levels Zero level
Virtual memory – paging Virtual address 31 12 11 Page number (PN) Offset Page table [0] flags Physical address [1] 31 12 11 GLUE Frame number (FN) Offset [PN-1] [PN] FN [PN+1] [MAXPN]
Multitasking, multiprocessing Multiple processes running simultaneously on OS Multiprocessing Multiple CPUs in one computer
Thread Thread Multiple activities in one process Starting thread Private stack for each thread Local variables, parameters, chain of function calls Context
Memory organization Code Constants Initialized static data Uninitialized static data Heap Stack for thread n Stack for thread 1
Race condition Race condition The output is dependent on sequence or timing of other uncontrollable events Preemptive scheduling type PRec = ^TRec; TRec = record val:integer; next:Prec; end; var list:PRec; C next D nil list
Race condition Initial state Correct state Incorrect state Thread 1 InsertList(Ap); procedure InsertList(node:PRec); begin node^.next:=list; list:=node; end; Thread InsertList(Bp); Initial state list X Y Correct state Incorrect state A list B A X Y list X Y Another correct state B list A B X Y