Clean Code



Download 3,58 Mb.
Pdf ko'rish
bet313/384
Sana05.04.2022
Hajmi3,58 Mb.
#530298
1   ...   309   310   311   312   313   314   315   316   ...   384
Bog'liq
Clean Code


Mutual exclusion

Lock & wait

No preemption

Circular wait
Mutual Exclusion
Mutual exclusion occurs when multiple threads need to use the same resources and those
resources 

Cannot be used by multiple threads at the same time.

Are limited in number.
A common example of such a resource is a database connection, a file open for write, a
record lock, or a semaphore. 
4.
For example, someone adds some debugging output and the problem “disappears.” The debugging code “fixes” the problem 
so it remains in the system. 


337
Deadlock
Lock & Wait
Once a thread acquires a resource, it will not release the resource until it has acquired all
of the other resources it requires and has completed its work.
No Preemption
One thread cannot take resources away from another thread. Once a thread holds a
resource, the only way for another thread to get it is for the holding thread to release it.
Circular Wait
This is also referred to as the deadly embrace. Imagine two threads, T1 and T2, and two
resources, R1 and R2. T1 has R1, T2 has R2. T1 also requires R2, and T2 also requires R1.
This gives something like Figure A-3:
All four of these conditions must hold for deadlock to be possible. Break any one of these
conditions and deadlock is not possible.
Breaking Mutual Exclusion
One strategy for avoiding deadlock is to sidestep the mutual exclusion condition. You
might be able to do this by

Using resources that allow simultaneous use, for example, 
AtomicInteger
.

Increasing the number of resources such that it equals or exceeds the number of com-
peting threads.

Checking that all your resources are free before seizing any.
Unfortunately, most resources are limited in number and don’t allow simultaneous
use. And it’s not uncommon for the identity of the second resource to be predicated on the
results of operating on the first. But don’t be discouraged; there are three conditions left.

Download 3,58 Mb.

Do'stlaringiz bilan baham:
1   ...   309   310   311   312   313   314   315   316   ...   384




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish