標籤:-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線程相互排斥量--進程共用屬性