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

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.

主站蜘蛛池模板: 阳泉市| 介休市| 河南省| 昌黎县| 三河市| 房山区| 浦县| 白玉县| 平顶山市| 乾安县| 桐城市| 广河县| 阳朔县| 南溪县| 林西县| 客服| 准格尔旗| 榆林市| 淮阳县| 香河县| 剑川县| 永清县| 容城县| 昌宁县| 南投市| 定州市| 长沙市| 长兴县| 岳池县| 江口县| 马边| 图木舒克市| 南康市| 南靖县| 浮梁县| 徐汇区| 千阳县| 无锡市| 观塘区| 华容县| 峨边|