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

The with statement in concurrent programming

Obviously, opening and closing external files does not resemble concurrency very much. However, we mentioned earlier that the with statement, as a context manager, is not only used to manage file descriptors, but most resources in general. And if you actually found managing lock objects from the threading.Lock() class similar to managing external files while going through Chapter 2, Amdahl's Law, then this is where the comparison between the two comes in handy.

As a refresher, locks are mechanisms in concurrent and parallel programming that are typically used to synchronize threads in a multithreaded application (that is, to prevent more than one thread from accessing the critical session simultaneously). However, as we will discuss again in Chapter 12, Starvation, locks are also a common source of deadlock, during which a thread acquires a lock but never releases it because of an unhandled occurrence, thereby stopping the entire program.

主站蜘蛛池模板: 五河县| 东平县| 沁源县| 达拉特旗| 陆丰市| 聂拉木县| 巴林右旗| 安泽县| 德惠市| 平度市| 云和县| 建瓯市| 九台市| 广德县| 漾濞| 志丹县| 康乐县| 朝阳区| 双桥区| 海淀区| 济南市| 昆明市| 山东| 龙井市| 洛扎县| 宁化县| 玉林市| 密山市| 姚安县| 莱州市| 德昌县| 安康市| 曲靖市| 峨眉山市| 灌阳县| 安顺市| 上犹县| 东方市| 丹寨县| 韩城市| 巴塘县|