- Mastering Concurrency in Python
- Quan Nguyen
- 160字
- 2021-06-10 19:24:03
The threading.Lock class
One of the most common ways to apply thread synchronization is through the implementation of a locking mechanism. In our threading module, the threading.Lock class provides a simple and intuitive approach to creating and working with locks. Its main usage includes the following methods:
- threading.Lock(): This method initializes and returns a new lock object.
- acquire(blocking): When this method is called, all of the threads will run synchronously (that is, only one thread can execute the critical section at a time):
- The optional argument blocking allows us to specify whether the current thread should wait to acquire the lock
- When blocking = 0, the current thread does not wait for the lock and simply returns 0 if the lock cannot be acquired by the thread, or 1 otherwise
- When blocking = 1, the current thread blocks and waits for the lock to be released and acquires it afterwards
- release(): When this method is called, the lock is released.
推薦閱讀
- Instant Zepto.js
- HTML5+CSS3網站設計基礎教程
- FFmpeg入門詳解:音視頻原理及應用
- Oracle JDeveloper 11gR2 Cookbook
- 從0到1:Python數據分析
- Frank Kane's Taming Big Data with Apache Spark and Python
- PHP與MySQL權威指南
- 官方 Scratch 3.0 編程趣味卡:讓孩子們愛上編程(全彩)
- Beginning PHP
- Mastering ArcGIS Server Development with JavaScript
- Visual FoxPro程序設計習題及實驗指導
- Pandas 1.x Cookbook
- Backbone.js Patterns and Best Practices
- JavaScript程序設計實例教程(第2版)
- PhoneGap 3.x Mobile Application Development Hotshot