檔案鎖

creasin ten region

File locking is a mechanism that enforces access to a computer file by only one user or process at any specific time. The purpose of locking is to prevent the classic interceding update scenario.
The interceding update problem may be illustrated as in the following example:
1. Process A reads a customer record from a file containing account information, including the customer's account balance and phone number.
2. Process B now reads the same record from the same file so it has its own copy.
3. Process A changes the account balance in its copy of the customer record and writes the record back to the file.
4. Process B--which still has the original stale value for the account balance in its copy of the customer record--updates the customer's phone number and writes the customer record back to the file.
5. Process B has now written its stale account balance value to the file, causing the changes made by process A to be lost.
File locking prevents this problem by enforcing the serialization of update processes to any given file. Most operating systems support the concept of record locking which means that individual records within any given file may be locked, so increasing the number of concurrent update processes.
One use of file locking is in database maintenance where it can serialize access to the entire physical file underlying a database. While this prevents any other process from accessing the file it can actually be more efficient than individually locking a large number of regions in the file by removing the overhead of achieving and releasing each lock.
中文翻譯:
檔案鎖定是一種機制,強制訪問計算機檔案只能由一個用戶或在任何特定時間的過程。鎖定的目的是要防止的惡意更新場景。調解更新的問題可能是在下面的例子所示:
1。一個進程讀取從一個檔案包含帳戶信息,包括客戶的帳戶餘額和電話號碼的客戶記錄。
2。進程B讀取相同的檔案相同的記錄,所以它有它自己的拷貝。
3。進程A在其客戶記錄副本的帳戶餘額的變化,並記錄寫回檔案。
4。進程B - 仍然有原始陳舊的價值在其客戶記錄副本的帳戶餘額 - 更新客戶的電話號碼,並寫入客戶記錄檔案。
5。進程B現在已經寫入了其過時的帳戶平衡值的檔案,造成到丟失的過程中所作的更改。
檔案鎖定防止這個問題,任何給定的檔案執行更新過程的系列化。大多數的作業系統都支持這意味著,在任何給定的的檔案的個人記錄可能會被鎖定,所以越來越多的並發更新過程的記錄鎖定的概念。在資料庫維護的檔案鎖定的用途之一是它可以序列化到整個底層資料庫的物理檔案的訪問。雖然這可以防止任何其他進程訪問檔案,它實際上可以被刪除每個鎖的實現和釋放開銷比單獨鎖定一個檔案中的地區大量更有效率。

相關詞條

相關搜尋

熱門詞條

聯絡我們