首页 > 其他 > 详细

Operating System: Three Easy Pieces --- Concurrency: An Introduction (Note)

时间:2015-11-05 00:16:48      阅读:354      评论:0      收藏:0      [点我收藏+]

Thus far, we have seen the development of the basic abstractions that the OS performs. We have

seen how to take a single physical CPU and turn it into multiple virtual CPUs, thus enabling the

illusion of multiple programs running at the same time. We have also seen how to create the

illusion of a large, private virtual memory for each process; this abstraction of the address space

enables each program to behave as if it has its own memory when indeed the OS is secretly

multiplexing address spaces across physical memory (and sometimes, disk).

In this note, we introduce a new abstraction for a single running process: that of a thread. 

Instead of our classic view of a single point of execution within a program (i.e., a single PC

where instructions are being fetched from and executed), a multi-threaded program has more

than one point of execution (i.e., multiple PCs, each of which is being fetched and executed

from). Perhaps another way to think of this is that each thread is very much like a separate

process, except for one difference: they share the same address space and thus can access

the same data.

The state of a single thread is thus very similar to that of a process. If has a program counter

(PC) that tracks where the private set of registers it uses for computation; thus, if there are two

threads of that are running on a single processor, when switching from running one (T1) to

running the other (T2), a context switch must take place. The context swtich between threads 

is quite similar to the context switch between processes, as the register state of T1 must be

saved and the register state of T2 restored before running T2. With processes, we saved state

to a process control block; now, we will need one or more thread control blocks to store the 

state of each thread of a process. There is one major difference, though, in the context switch

we perform between threads as compared to processes: the address space remains the same

(i.e., there is no need to switch which page table we are using).

One other major difference between threads and processes concerns the stack. In our simple

model of the address space of a classic process (which we can now call a single-threaded

process), there is a single stack, usually residing at the bottom of the address space.

 

Operating System: Three Easy Pieces --- Concurrency: An Introduction (Note)

原文:http://www.cnblogs.com/miaoyong/p/4937744.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!