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

The concept of thread synchronization

Before we jump into an actual Python example, let's explore the concept of synchronization in computer science. As you saw in previous chapters, sometimes, it is undesirable to have all portions of a program execute in a parallel manner. In fact, in most contemporary concurrent programs, there are sequential portions and concurrent portions of the code; furthermore, even inside of a concurrent portion, some form of coordination between different threads/processes is also required.

Thread/process synchronization is a concept in computer science that specifies various mechanisms to ensure that no more than one concurrent thread/process can process and execute a particular program portion at a time; this portion is known as the critical section, and we will discuss it in further detail when we consider common problems in concurrent programming in Chapter 12, Starvation, and Chapter 13, Race Conditions.

In a given program, when a thread is accessing/executing the critical section of the program, the other threads have to wait until that thread finishes executing. The typical goal of thread synchronization is to avoid any potential data discrepancies when multiple threads access their shared resources; allowing only one thread to execute the critical section of the program at a time guarantees that no data conflicts occur in multithreaded applications.

主站蜘蛛池模板: 郑州市| 家居| 微山县| 宁武县| 大城县| 腾冲县| 余干县| 密云县| 玛纳斯县| 萨嘎县| 大埔县| 肃南| 泸溪县| 白银市| 荥阳市| 延边| 清镇市| 公主岭市| 德格县| 安徽省| 南丹县| 甘谷县| 北辰区| 方正县| 阿拉善左旗| 澜沧| 兴化市| 五华县| 叶城县| 房产| 天津市| 峨边| 通海县| 济南市| 化德县| 吉林省| 青阳县| 宁安市| 鄂托克旗| 资溪县| 文水县|