2011年12月7日星期三

modern operating system 3rd edition 2

processes&threads
in UNIX,all processes belong to a single tree,with init at the root.However,in Windows,there is no concept of process hierachy.
process table:
threads can work quasi-paralell and sharing the address space,but process can only work paralell,not sharing address space.secondly,thread switching is faster and lighter weight.threads are useful on multi-core processors.
process are used to group resources together,and threads are entities scheduled for ecution on CPU.
Problems:what happens when a multithread process forks?
how to implemeting threads?
1.totally in user space:each process keeps its private thread table
2.totally in kernel:way slower
3.hybrid

IPC:
avoid race condition(in other words, achive mutual exclusive)
disabling interupts:it is a hardware solution and is not useful if it is multi-processor,and it is very dangerous
lock variable:(software solution)has fatal flaw
turn variable:two process must strict alternation,which can not always be true(so it has fatal flaw too)
Peterson's solution:enter_region()&leave_region()(it works,but has defect--busy waiting,which wasts CPU)
sleep&wakuup:it works and not busy-waiting, but blocks(which means a blocked process need to be wakeup by another process)
semaphore(Dijkstra proposed, ans is an variant from sleep&wakeup)
semaphore can be used in two different way:mutual exclusive(semaphore can be simplified as mutex)and synchronization(producer-consumer problem)

computer-bound:process which spends most time computing
I/O-bound:process which spends most time waiting for I/O

没有评论:

发表评论