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

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.

主站蜘蛛池模板: 潢川县| 平山县| 汕尾市| 宁化县| 大城县| 依安县| 丹棱县| 吴旗县| 临猗县| 阿坝县| 无棣县| 南溪县| 渑池县| 报价| 合水县| 洪湖市| 和田市| 汤阴县| 崇文区| 益阳市| 河北省| 黄石市| 灵山县| 同心县| 龙岩市| 龙井市| 留坝县| 常德市| 仁寿县| 南溪县| 蒙山县| 大姚县| 兴宁市| 大埔区| 大兴区| 屏东县| 什邡市| 台中市| 陆河县| 金平| 绥江县|