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

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.

主站蜘蛛池模板: 习水县| 贞丰县| 岳池县| 海兴县| 正定县| 蓬溪县| 通城县| 瓮安县| 潼南县| 藁城市| 肇庆市| 紫云| 吴川市| 关岭| 五台县| 临清市| 文昌市| 吉隆县| 安吉县| 花莲县| 龙泉市| 兖州市| 双辽市| 文昌市| 华池县| 娱乐| 额济纳旗| 青田县| 吴江市| 卢龙县| 观塘区| 石柱| 正宁县| 淳化县| 武胜县| 利川市| 武平县| 固阳县| 崇左市| 资兴市| 宝清县|