官术网_书友最值得收藏!

Concurrency in a breeze

We start with a simple definition. When things happen at the same time, we say that things are happening concurrently. As far as this book is concerned, whenever parts of an executable program run at the same time, we are dealing with concurrent programming. We use the term parallel programming as a synonym for concurrent programming.  

The world is full of concurrent occurrences. Let's look at a real-life example. Say that there are a certain number of cars driving on a multilane highway. In the same lane, though, cars need to follow other cars, the ones that are already ahead of them. A road lane, in this case, is a resource to be shared. 

When a toll plaza is built, however, things change. Each car stops in its lane for a minute or two to pay the toll and collect a receipt. While the toll attendant is engaged with the car, other cars behind it need to queue up and wait. However, a toll plaza has more than one payment gate. There are attendants at each gate, attending to different cars at the same timeIf there are three attendants, each serving one gate, then three cars could pay the toll at the same point in time; that is, they can get serviced in parallel, as shown in the following diagram:      

Note that the cars queuing up at the same booth get serviced in sequence. At any given time, a toll attendant can service only one car, so others in the queue need to wait for their turn. 

It would be really odd to see a toll booth with just one gate! People wouldn't be served in parallelStrictly sequential processing of toll charges would make life unbearable for the frequent traveler.

Even when there are multiple gates and an abnormally large influx of cars (say on vacations), each gate becomes a bottleneck; there are far fewer resources for servicing the workload.     

主站蜘蛛池模板: 乌什县| 黄大仙区| 阳泉市| 邓州市| 荔浦县| 宣城市| 河北省| 都江堰市| 万安县| 盘山县| 榕江县| 会昌县| 桐乡市| 巴林右旗| 西畴县| 南陵县| 石嘴山市| 昭平县| 怀来县| 万山特区| 怀来县| 南通市| 措美县| 温泉县| 鸡东县| 阳春市| 马公市| 鄂尔多斯市| 米泉市| 军事| 泗洪县| 德州市| 苍梧县| 大新县| 屏山县| 凤翔县| 皮山县| 石柱| 十堰市| 崇州市| 双流县|