linux系統(tǒng)課程-課件09day09線程同步2其他_第1頁(yè)
linux系統(tǒng)課程-課件09day09線程同步2其他_第2頁(yè)
linux系統(tǒng)課程-課件09day09線程同步2其他_第3頁(yè)
linux系統(tǒng)課程-課件09day09線程同步2其他_第4頁(yè)
linux系統(tǒng)課程-課件09day09線程同步2其他_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

讀寫鎖的特點(diǎn):讀共享,寫?yīng)氄迹瑢憙?yōu)先級(jí)高讀寫鎖仍然是一把鎖,有不同的狀態(tài):讀寫讀寫鎖場(chǎng)景練習(xí)線程A加寫鎖成功 線程B請(qǐng)求讀線程B線程A持有讀鎖 線程B請(qǐng)求寫線程B線程A擁有讀鎖 線程B請(qǐng)求讀B加鎖 BCA釋放后,BB釋放后,C線程A持有寫鎖 然后線程B請(qǐng)求讀鎖 然后程C請(qǐng)求BC阻A釋放,C加C釋放,B加constpthread_rwlockattr_t*restrictattr);pthread_rwlock_trwlock=銷毀讀intintintint條件變 條件變量不是所,要和互斥量-pthread_mutex_t*restrictmutex,structtimespec}

time_t longtv_nsec;/*nanosecondes*tv_sec絕對(duì)時(shí)間,填寫的時(shí)候time(NULL)+600==>設(shè)置超時(shí)條件變量阻塞pthread_mutex_t*restrict先釋放鎖阻塞在cond條件變量上intpthread_cond_destroy(pthread_cond_t初始化一個(gè)條constpthread_condattr_t*restrictattr);intpthread_cond_broadcast(pthread_cond_t條件變量的作用:避免無(wú)必要內(nèi)容 創(chuàng)建線程回收線程線程退出pthread_exit殺死線程pthread_cancel線程分離pthread_detach,也可以通過(guò)屬性設(shè)置pthread_attr_setdetachstate設(shè)置屬性分離,之前需要查看線程IDpthread_self在進(jìn)程內(nèi)唯一 信號(hào)量是進(jìn)化版的互斥量,允許多個(gè)線程共享資intsem_init(sem_t*sem,intpshared,unsignedintsem定義的信號(hào)量0代表線程信非0代表進(jìn)程信value定義信號(hào)量的sem_destroy摧毀信號(hào)intsem_destroy(sem_t*sem);申請(qǐng)信號(hào)量,申請(qǐng)成功value--intsem_wait(sem_t*sem);釋放信號(hào)量value++intsem_post(sem_t分區(qū)linux-day09-線程同步的第9 實(shí)現(xiàn)常見(jiàn)兩個(gè)現(xiàn)象的死鎖,鎖了又鎖以及交叉實(shí)現(xiàn)哲學(xué)家分區(qū)linux-day09-線程同步的第10errno #defineEPERM 1/*Operationnotpermitted*/#defineENOENT 2/*Nosuchfileordirectory*/#defineESRCH 3/*Nosuchprocess*/#defineEINTR /*Interruptedsystemcall*/#defineEIO /*I/Oerror*/#defineENXIO /*Nosuchdeviceoraddress*/#defineE2BIG /*Argumentlisttoolong*/#defineENOEXEC /*Execformaterror*/#defineEBADF /*Badfilenumber*/#defineECHILD /*Nochildprocesses*/#defineEAGAIN /*Tryagain*/#defineENOMEM12/*Outofmemory*/#defineEACCES13/*Permissiondenied*/#defineEFAULT14/*Badaddress*/#defineENOTBLK15/*Blockdevicerequired*/#defineEBUSY 16/*Deviceorresourcebusy*/#defineEEXIST17/*Fileexists*/#defineEXDEV /*Cross-devicelink*/#defineENODEV /*Nosuchdevice*/#defineENOTDIR /*Notadirectory*/#defineEISDIR /*Isadirectory*/#defineEINVAL 22 /*Invalidargument*/#defineENFILE /*Filetableoverflow*/#defineEMFILE 24 /*Toomanyopenfiles*/#defineENOTTY /*Notatypewriter*/#defineETXTBSY /*Textfilebusy*/#defineEFBIG /*Filetoolarge*/#defineENOSPC /*Nospaceleftondevice*/#defineESPIPE /*Illegalseek*/#defineEROFS /*Read-onlyfilesystem*/#defineEMLINK /*Toomanylinks*/ /*Brokenpipe /*Mathargumentoutofof /*Mathresultnotrepresentable#defineEDEADLK /*Resourcedeadlockwouldoccur*/#defineENALONG /*Filenametoolong*/#defineENOLCK /*Norecordlocksavailable*/#defineENOSYS /*Invalidsystemcallnumber*/#defineENOTEMPTY /*Directorynotempty*/ /*Toomanysymboliclinks#defineEWOULDBLOCK EAGAIN/*Operationwouldblock*/#defineENOMSG /*Nomessageofdesiredtype*/#defineEIDRM /*Identifierremoved*/#defineECHRNG /*Channelnumberoutofrange*/#defineEL2NSYNC /*Level2notsynchronized*/#defineEL3HLT /*Level3halted*/ /*Level3reset#defineELNRNG /*Linknumberoutofrange*/#defineEUNATCH /*Protocoldrivernotattached*/#defineENOCSI /*NoCSIstructureavailable*/#defineEL2HLT /*Level2halted*/ /*Invalidexchange#defineEBADR 53 /*Invalidrequestdescriptor*/#defineEXFULL /*Exchangefull*/ /*Noanode#defineEBADRQC /*Invalidrequestcode*/#defineEBADSLT /*Invalidslot*/ #defineEBFONT /*Badfontfileformat*/#defineENOSTR /*Devicenotastream*/#defineENODATA /*Nodataavailable*/#defineETIME /*Timerexpired*/ /*Outofstreamsresources#defineENONET /*Machineisnotonthenetwork*/#defineENOPKG 65 /*Packagenotinstalled*/#defineEREMOTE /*Objectisremote*/#defineENOLINK /*Linkhasbeensevered*/#defineEADV /*Advertiseerror*/ /*Srmounterror#defineECOMM /*Communicationerroronsend*/#defineEPROTO /*Protocolerror*/#defineEMULTIHOP /*Multihopattempted*/#defineEDOTDOT /*RFSspecificerror*/#defineEBADMSG /*Notadatamessage*/#defineEOVERFLOW /*Valuetoolargefordefineddatatype*/#defineENOTUNIQ /*Namenotuniqueonnetwork*/#defineEBADFD /*Filedescriptorinbadstate*/#defineEREMCHG /*Remoteaddresschanged*/ /*Cannotaccessaneededshared#defineELIBBAD 80 /*Accessingacorruptedsharedlibrary*/ /*.libsectionina.outcorrupted*/#defineELIBMAX /*Attemptingtolinkintoomanysharedlibraries*/ /*Cannotexecasharedlibrary /*Illegalbytesequence#defineERESTART /*Interruptedsystemcallshouldberestarted*/#defineESTRPIPE /*Streamspipeerror*/#defineEUSERS /*Toomanyusers*/#defineENOTSOCK88/*Socketoperationonnon-socket*/#defineEDESTADDRREQ89/*Destinationaddressrequired*/#defineEMSGSIZE90/*Messagetoolong*/#defineEPROTOTYPE /*Protocolwrongtypeforsocket*/#defineENOPROTOOPT /*Protocolnotavailable*/#defineEPROTONOSUPPORT93 /*Protocolnotsupported*/#defineESOCKTNOSUPPORT94 /*Sockettypenotsupported*/#defineEOPNOTSUPP /*Operationnotsupportedontransportendpoint*/ /*Protocolfamilynotsupported#defineEAFNOSUPPORT /*Addressfamilynotsupportedbyprotocol*/ /*Addressalreadyinuse /*Cannotassignrequested /*Networkisdown#defineENETUNREACH101/*Networkisunreachable*/#defineENETRESET102/*Networkdroppedconnectionbecauseofreset*/#defineECONNABORTED103/*Softwarecausedconnectionabort*/#defineECONNRESET104/*Connectionresetbypeer#define/*Nobufferspaceavailable#define/*Transportendpointisconnected#defineENOTCONN /*Transportendpointisnotconnected*/#defineESHUTDOWN /*Cannotsendaftertransportendpointshutdown*/#defineETOOMANYREFS /*Toomanyreferences:cannotsplice*/#defineETIMEDOUT /*Connectiontimedout*/#defineECONNREFUSED /*Connectionrefused*/#defineEHOSTDOWN /*Hostisdown*/#defineEHOSTUNREACH /*Noroutetohost*

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論