Linux線程相互排斥量--進程共用屬性

來源:互聯網
上載者:User

標籤:-shared   mit   ring   ++   initial   cti   加鎖   ack   zed   

多線程中。在相互排斥量和 讀寫鎖的 屬性中。都有一個叫 進程共用屬性 。

對於相互排斥量,查詢和設定這個屬性的方法為:
pthread_mutexattr_getpshared
pthread_mutexattr_setpshared

我一開始不理解什麼是 進程共用屬性。 看了man中的說明例如以下

The pthread_mutexattr_getpshared() function shall obtain the value of the process-shared attribute from the attributes object referenced by attr. The pthread_mutexattr_setpshared() function shall set the process-shared attribute in an initialized attributes object referenced by attr.

The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a mutex to be operated upon by any thread that has access to the memory where the mutex is allocated, even if the mutex is allocated in memory that is shared by multiple processes. If the process-shared attribute is PTHREAD_PROCESS_PRIVATE, the mutex shall only be operated upon by threads created within the same process as the thread that initialized the mutex; if threads of differing processes attempt to operate on such a mutex, the behavior is undefined. The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE.

意思是:
這個屬性有兩個值
PTHREAD_PROCESS_SHARED
PTHREAD_PROCESS_PRIVATE, 顧名思義。是進程共用,和進程不共用。 也即是 當你的進程初始化一個相互排斥量後, 是僅僅有自己的進程 能夠使用,還是 其它進程也能夠使用這個相互排斥量。


預設情況是 PTHREAD_PROCESS_PRIVATE。 僅僅有本進程能夠 對這個相互排斥量加鎖等操作。
這時。別的進程。對私人的 相互排斥量 操作的行為。未定義。

Linux線程相互排斥量--進程共用屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.