欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Linux多線程鎖屬性設置方法

 更新時間:2017年01月05日 10:16:30   投稿:jingxian  
下面小編就為大家?guī)硪黄狶inux多線程鎖屬性設置方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

互斥鎖是Linux下多線程資源保護的常用手段,但是在時序復雜的情況下,很容易會出現(xiàn)死鎖的情況。

可以通過設置鎖的屬性,避免同一條線程重復上鎖導致死鎖的問題。

通過int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)接口設置

一般是以下四種屬性:

PTHREAD_MUTEX_NORMAL
This type of mutex does not detect deadlock. A thread attempting to relock this mutex without first unlocking it will deadlock. Attempting to unlock a mutex locked by a different thread results in undefined behaviour. Attempting to unlock an unlocked mutex results in undefined behaviour.

PTHREAD_MUTEX_ERRORCHECK
This type of mutex provides error checking. A thread attempting to relock this mutex without first unlocking it will return with an error. A thread attempting to unlock a mutex which another thread has locked will return with an error. A thread attempting to unlock an unlocked mutex will return with an error.

PTHREAD_MUTEX_RECURSIVE
A thread attempting to relock this mutex without first unlocking it will succeed in locking the mutex. The relocking deadlock which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. Multiple locks of this mutex require the same number of unlocks to release the mutex before another thread can acquire the mutex. A thread attempting to unlock a mutex which another thread has locked will return with an error. A thread attempting to unlock an unlocked mutex will return with an error.

PTHREAD_MUTEX_DEFAULT
Attempting to recursively lock a mutex of this type results in undefined behaviour. Attempting to unlock a mutex of this type which was not locked by the calling thread results in undefined behaviour. Attempting to unlock a mutex of this type which is not locked results in undefined behaviour. An implementation is allowed to map this mutex to one of the other mutex types.

這里主要指同一條線程重復上鎖,不同線程上鎖,無論設置什么屬性,當鎖已經(jīng)被鎖定后都會互斥阻塞。

使用PTHREAD_MUTEX_RECURSIVE屬性,當同一條線程在沒有解鎖的情況下嘗試再次鎖定會返回成功。

以上就是小編為大家?guī)淼腖inux多線程鎖屬性設置方法全部內(nèi)容了,希望大家多多支持腳本之家~

相關文章

  • ubuntu中python調(diào)用C/C++方法之動態(tài)鏈接庫詳解

    ubuntu中python調(diào)用C/C++方法之動態(tài)鏈接庫詳解

    這篇文章主要給大家介紹了關于如何在ubuntu中python調(diào)用C/C++方法之動態(tài)鏈接庫的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起看看吧
    2018-11-11
  • CentOS6.6詳細安裝教程(圖文教程)

    CentOS6.6詳細安裝教程(圖文教程)

    這篇文章主要介紹了CentOS6.6詳細安裝教程(圖文教程),對初學者有一定的參考價值,有需要的可以了解一下。
    2016-10-10
  • apache的access.log和error.log減肥

    apache的access.log和error.log減肥

    我的服務器是用apache搭建的,里面的access.log和error.log這兩個文件要經(jīng)常上去看,和清理,如果時間忙,忘記看和清理了,過不了多久,這兩個文件就膨脹的非常的大,打都打不開了。
    2009-09-09
  • Ubuntu18.04(linux)安裝MySQL的方法步驟

    Ubuntu18.04(linux)安裝MySQL的方法步驟

    本篇文章主要介紹了Ubuntu18.04(linux)安裝MySQL的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-05-05
  • Linux下安裝MariaDB數(shù)據(jù)庫問題及解決方法(二進制版本的安裝)

    Linux下安裝MariaDB數(shù)據(jù)庫問題及解決方法(二進制版本的安裝)

    MariaDB數(shù)據(jù)庫 分為源代碼版本和二進制版本,源代碼版本需要cmake編譯,這里是二進制版本的安裝。下面通過本文給大家介紹Linux下安裝MariaDB數(shù)據(jù)庫問題及解決方法(二進制版本的安裝),感興趣的朋友參考下吧
    2016-11-11
  • Linux系統(tǒng)下Nginx支持ipv6配置的方法

    Linux系統(tǒng)下Nginx支持ipv6配置的方法

    這篇文章主要介紹了Linux系統(tǒng)下Nginx支持ipv6的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-12-12
  • 關于在Linux下如何搭建DNS服務器

    關于在Linux下如何搭建DNS服務器

    這篇文章主要介紹了關于在Linux下如何搭建DNS服務器,文中提供了部分實現(xiàn)代碼和解決思路,有一定的參考價值,需要的朋友快來一起看看吧
    2023-04-04
  • Linux進程間通信方式之socket使用實例

    Linux進程間通信方式之socket使用實例

    這篇文章主要介紹了Linux進程間通信方式之socket使用實例,具有一定參考價值,需要的朋友可以了解下。
    2017-11-11
  • 在CentOS 7上給一個網(wǎng)卡分配多個IP地址的方法

    在CentOS 7上給一個網(wǎng)卡分配多個IP地址的方法

    本篇文章主要介紹了在CentOS 7上給一個網(wǎng)卡分配多個IP地址的方法,具有一定的參考價值,有需要的可以了解一下。
    2017-03-03
  • Linux內(nèi)核設備驅動之內(nèi)核中鏈表的使用筆記整理

    Linux內(nèi)核設備驅動之內(nèi)核中鏈表的使用筆記整理

    今天小編就為大家分享一篇關于Linux內(nèi)核設備驅動之內(nèi)核中鏈表的使用筆記整理,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-12-12

最新評論