Qhov txawv ntawm Semaphore thiab Saib Xyuas

Qhov txawv ntawm Semaphore thiab Saib Xyuas
Qhov txawv ntawm Semaphore thiab Saib Xyuas

Video: Qhov txawv ntawm Semaphore thiab Saib Xyuas

Video: Qhov txawv ntawm Semaphore thiab Saib Xyuas
Video: Насколько важны YouTube видео для роста бизнеса | Идеи YouTube... 2024, Lub Xya hli ntuj
Anonim

Semaphore vs Monitor

Semaphore yog cov qauv ntaub ntawv uas siv los xyuas kom meej tias ntau cov txheej txheem tsis nkag mus rau cov peev txheej lossis cov ntu tseem ceeb tib lub sijhawm, nyob rau hauv ib puag ncig kev sib txuas. Semaphores yog siv los tiv thaiv cov xauv tuag thiab kev sib tw. Monitor yog ib hom lus programming tsim uas tseem siv los zam ntau cov txheej txheem nkag mus rau ib qho kev pab cuam tib lub sijhawm yog li lav kev sib nrig sib cais. Cov saib xyuas siv cov kev hloov pauv hloov pauv kom ua tiav txoj haujlwm no.

Semaphore yog dab tsi?

Semaphore yog cov qauv ntaub ntawv uas siv los muab kev sib nrig sib cais rau cov ntu tseem ceeb. Semaphores feem ntau txhawb nqa ob txoj haujlwm hu ua tos (keeb kwm hu ua P) thiab teeb liab (keeb kwm hu ua V). Lub sijhawm tos ua haujlwm thaiv cov txheej txheem kom txog thaum lub semaphore qhib thiab lub teeb liab ua haujlwm tso cai rau lwm cov txheej txheem (xov) nkag. Txhua semaphore yog txuam nrog ib tug queue ntawm tos txheej txheem. Thaum lub sijhawm ua haujlwm tos raug hu los ntawm xov, yog tias lub semaphore qhib, cov xov tuaj yeem txuas ntxiv mus. Yog tias lub semaphore raug kaw thaum lub sijhawm tos kev ua haujlwm raug hu los ntawm cov xov, cov xov raug thaiv thiab nws yuav tsum tau tos hauv cov kab. Lub teeb liab ua haujlwm qhib lub semaphore thiab yog tias muaj cov xov uas twb tau tos hauv cov kab, cov txheej txheem ntawd raug tso cai mus txuas ntxiv thiab yog tias tsis muaj cov xov tos nyob rau hauv kab lub teeb liab yuav nco ntsoov rau cov xov tom ntej. Muaj ob hom semaphores hu ua mutex semaphores thiab suav semaphores. Mutex semaphores tso cai rau ib qho kev nkag mus rau cov peev txheej thiab suav cov semaphores tso cai rau ntau cov xov kom nkag mus rau cov peev txheej (uas muaj ntau chav nyob).

Tus Saib Xyuas yog dab tsi?

A saib yog ib hom lus programming tsim uas yog siv los tswj kev nkag mus rau cov ntaub ntawv sib koom. Cov saib xyuas encapsulate sib koom cov ntaub ntawv qauv, cov txheej txheem (uas ua haujlwm ntawm cov ntaub ntawv sib koom) thiab synchronization ntawm cov txheej txheem invocations. Tus saib xyuas kom paub tseeb tias nws cov ntaub ntawv tsis raug cuam tshuam nrog kev nkag tsis tau thiab lav tias treads (uas nkag mus saib cov ntaub ntawv los ntawm nws cov txheej txheem) cuam tshuam raws li txoj cai. Tus saib xyuas tau lees tias kev sib nrig sib cais los ntawm kev tso cai tsuas yog ib qho xov los ua cov txheej txheem saib xyuas ntawm ib lub sijhawm. Yog tias lwm txoj xov sim hu rau ib txoj hauv kev saib xyuas, thaum lub xov tseem tab tom ua tiav cov txheej txheem hauv lub saib, ces cov txheej txheem thib ob raug thaiv thiab nws yuav tsum tau tos hauv kab. Muaj ob hom kev saib xyuas hu ua Hoare saib thiab Mesa saib. Lawv feem ntau txawv nyob rau hauv lawv lub sijhawm teem sijhawm semantics.

Qhov txawv ntawm Semaphore thiab Monitor yog dab tsi?

Txawm hais tias ob qho tib si semaphores thiab cov saib xyuas tau siv los ua kom muaj kev sib koom ua ke nyob rau hauv ib puag ncig kev sib koom ua ke, lawv sib txawv hauv cov txheej txheem siv los ua tiav txoj haujlwm no. Hauv kev saib xyuas, cov cai uas siv los ua kom tau txais kev sib nrig sib cais yog nyob rau hauv ib qho chaw thiab muaj ntau yam qauv, thaum code rau semaphores raug faib raws li tos thiab teeb liab muaj nuj nqi hu. Tsis tas li ntawd, nws yooj yim heev rau kev ua yuam kev thaum siv cov semaphores, thaum muaj lub caij nyoog tsawg heev los ua yuam kev thaum siv cov saib. Tsis tas li ntawd, cov neeg saib xyuas siv cov xwm txheej hloov pauv, thaum cov semaphores tsis ua.

Pom zoo: