同步鎖–摘自《unix網路編程》第二卷

來源:互聯網
上載者:User

關於互斥:
When a mutex is shared between processes, there is always a chance that the process can terminate (perhaps involuntarily) while holding the mutex lock. There is no way to have the system automatically release held locks upon process termination. We will see that read-write locks and Posix semaphores share this property. The only type of synchronization locks that the kernel always cleans up automatically upon process termination is fcntl record locks(Chapter 9). When using System V semaphores, the application chooses whether a semaphore lock is automatically cleaned up or not by the kernel upon process termination (the SEM_UNDO feature that we talk about in Section 11.3).

書中還提到:
即使一個進程終止時系統自動釋放某個鎖,那也可能解決不了問題。
該鎖保護某個臨界區很可能是為了在執行該臨界區代碼期間更新某個資料。
如果該進程在執行該臨界區的中途終止,該資料處於什麼狀態呢?該資料處於不一致狀態的可能性很大。
如果核心僅僅在進程終止時自動解鎖的話,通常於事無補。
需要小心使用。

關於Posix有名號誌:
“關閉一個號誌並沒有將它從系統中刪除。這就是說,
Posix有名號誌至少是隨核心持續的:即使當前沒有進程開啟著某個號誌,它的值仍然保持。”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.