Vim li cas Pthread_cond_wait xav tau mutex?
Vim li cas Pthread_cond_wait xav tau mutex?

Video: Vim li cas Pthread_cond_wait xav tau mutex?

Video: Vim li cas Pthread_cond_wait xav tau mutex?
Video: Yog vim li cas Cover new Music By ajan povthoj MV Officail 2024, Kaum ib hlis
Anonim

Cov mutex yog siv los tiv thaiv tus mob sib txawv nws tus kheej. Yog vim li cas koj xav tau nws kaw ua ntej koj ua ib tos. Tom qab ntawd thaum cov xwm txheej hloov pauv tau raug teeb tsa lossis tshaj tawm rau, ib lossis ntau dua ntawm cov xov ntawm cov npe tos yuav raug tsa thiab mutex yuav tau tej yam yees siv kaw dua rau txoj xov ntawd.

Hais txog qhov no, puas yog Pthread_cond_wait qhib mutex?

Cov pthread_cond_wait () muaj nuj nqi thaiv cov xov tooj ntawm cov xwm txheej sib txawv cond, thiab qhib qhov cuam tshuam mutex mutex . Lub xov tooj hu yuav tsum tau xauv mutex ua ntej tos ntawm qhov kev hloov pauv. Thaum rov qab los ntawm kev ua haujlwm, lub mutex rov raug kaw thiab muaj los ntawm kev hu xov tooj.

Tom qab ntawd, lo lus nug yog, vim li cas mutex xav tau? Nws ua kom ntseeg tau tias tsuas yog ib qho xov yog ua tiav ib qho tseem ceeb ntawm cov lej ntawm ib lub sijhawm, uas dhau los txwv kev nkag mus rau cov qauv ntaub ntawv. Nws ua kom ntseeg tau tias ob txoj xov muaj tag nrho thiab tsim nyog saib ntawm lub cim xeeb tsis hais txog kev hloov pauv CPU. Cov mutex Nws yog ib qho tseem ceeb uas yuav tsum tau ua thaum ua cov programming ib txhij.

Ib sab saum toj no, vim li cas cov xwm txheej hloov pauv xav tau mutex?

Cov mutex yog siv los tiv thaiv cov yam hloov pauv tau nws tus kheej. Yog vim li cas koj xav tau nws kaw ua ntej koj ua ib tos. Tom qab ntawd thaum lub condition variable yog signaled los yog tshaj tawm rau, ib los yog ntau tshaj ntawm threads nyob rau hauv daim ntawv tos yuav ua tsaug thiab os mutex yuav yuav tej khawv koob xauv dua rau cov xov ntawd.

Vim li cas peb thiaj xav tau cov kev hloov pauv?

Condition variables cia ib txheej xov los pw kom txog thaum tickled! Koj tuaj yeem tickle ib txoj xov lossis tag nrho cov xov uas tsaug zog. Yog tias koj tsuas yog tsa ib txoj xov xwb ces lub operating system yuav txiav txim siab seb cov xov twg yuav sawv.

Pom zoo: