并发编程基础 Lecture Notes(一)

来源:互联网 发布:莫宁职业生涯数据 编辑:程序博客网 时间:2024/06/05 09:58

多个单核CPU VS 单个多核CPU

每个单核CPU都有独立的电路和cache支持。而多核CPU共享一套芯片组,一套存储,因此,多核之间的通信看起来就变得比多个单核CPU开销要小。但是,数据的共享性又给多核CPU带来了分时开销。


Concurrency:a collection of programs is said to be concurrent if at a given point in time, any of the programs may be the next one to execute its next atomic instruction. It could make better use of resources(time, space etc.)


Shared memory(read and write shared objects in memory), for example:


- A and B might be two threads in the same JAVA program sharing the same JAVA objects

- A and B might be two programs sharing common file

- A and B might be two processors sharing the same physical memory


Message passing(concurrent modules interact by sending message to each other through a communication channel, the messages queue up for handling), for example:


- two hosts communicate by network connections

- web browser and server

- instant messaging client and server

- two programs connect by a pipe


Synchronization:

- mutual exclusion

- condition synchronisation


Process: the execution of a sequential program

Atomic action: a programming instruction which changes a state of a system indivisibly, it can't be interrupted by an instruction from another process

Interleaving: each sequential program is listed in correct order in the interleaving, but the actions of different sequential components can be intermixed


Hardware assumptions:

- read and write from memory(considering the 8-byte long type data situation, things would be different)
- use a variable x, read x from memory and load it into a register, manipulate it inside registers, store the results back in memory

- each process has its private registers and a private stack which are saved when there is a process switch

- shared memory assumption: global variables


y = x + 1

R2 = x

R2 = R2 + 1

y = R2


Reference:

1. The Materials of Concurrent && Distributed Systems Course

0 0