Linux pthread_mutex_init()函數

來源:互聯網
上載者:User

   函數原型:Int  pthread_mutex_init(pthread_mutex_t  *restrict_mutex,const pthread_mutextattr_t *restrict attr)
    該函數主要用於多線程中互斥鎖的初始化。
   如果attr為空白的話,則是預設屬性,而預設屬性的快速互斥鎖。
   pthread_mutex_init完成成功後會返回0,其他值都是錯誤的。
   int pthread_mutextattr_destroy(pthread_mutextattr_t *restrict_mutext)
   該函數是銷毀線程互斥鎖
   設定互斥鎖的範圍:
    Int pthread_mutextattr_setpshared(pthread_mutexattr_t *restrict mutext, int pshared)
    在多線程中是共用互斥鎖的。
    如果想在多個進程中共用互斥鎖,可以把pshared設定PTHREAD_PROCESS_SHARED
    如果只想在有同屬於一個進程建立的線程中共用互斥鎖,則可以把pshared設定為PTHREAD_PROCESS_PRIVATE
    獲得互斥鎖的範圍:
     int pthread_mutexattr_getpshared(pthread_mutexattr_t *restrict mutext,int *pshared);
     設定互斥鎖類型的屬性:
     int pthread_mutexattr_settype(pthread_mutexattr_t *restrict mutext,int type)
     其中type類型都有:
    PTHREAD_MUTEX_NOMRAL:此類型的互斥鎖不會檢測死結
    而其中的預設值值是PTHREAD_MUTEX_DEFAULT
     PTHREAD_MUTEX_ERRORCHECK:是提供錯誤檢查
     int pthread_mutexattr_setprotocal(pthread_mutexattr_t *attr,int protocal)
     protocal可以設定互斥鎖屬性的協議
     PTHREAD_PRIO_NONE
     PTHREAD_PRIO_INHERIT
     PTHREAD_PRIO_PROTECT

作者“舞者部落格”

聯繫我們

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