Professional Documents
Culture Documents
Methods of Handling Deadlock
Methods of Handling Deadlock
A. The first solution is the one used by most operating systems, including Linux and
Windows. It is cheaper than the other approaches because in many systems,
deadlocks occur infrequently.
B. To ensure that deadlocks never occur, the system can use either a deadlock
prevention or a deadlock-avoidance scheme.
إنها أرخص من الطرق األخرىWindows. وLinux بما في ذلك، الحل األول هو الذي تستخدمه معظم أنظمة التشغيل
. تحدث المآزق بشكل غير منتظم، ألنه في العديد من األنظمة
يمكن للنظام استخدام نظام منع حدوث طريق مسدود أو نظام تجنب طريق، لضمان عدم حدوث حاالت الجمود مطلقًا
.مسدود
1. Deadlock prevention provides a set of methods to ensure that at least one of the
necessary conditions cannot hold.
2. Deadlock avoidance requires that the operating system be given additional
information in advance concerning which resources a thread will request and use
during its lifetime.
ً يوفر منع الجمود مجموعة من الطرق للتأكد من أن شر-1
.طا واحدًا على األقل من الشروط الضرورية ال يمكن أن يصمد
يتطلب تجنب حالة توقف تام أن يتم إعطاء نظام التشغيل معلومات إضافية مسبقًا بخصوص الموارد التي سيطلبها مؤشر-2
.الترابط ويستخدمها أثناء عمره
C.If a system does not employ either a deadlock-prevention or a deadlock avoidance
algorithm, then a deadlock situation may arise The system can provide an algorithm to
detect the deadlock and an algorithm to recover from it.
يمكن للنظام توفير خوارزمية. فقد تنشأ حالة توقف تام، إذا كان النظام ال يستخدم خوارزمية منع الجمود أو تجنب الجمود
.الكتشاف حالة الجمود وخوارزمية للتعافي منه
Deadlock Prevention
A. By ensuring that at least one of the four necessary conditions cannot hold, we can
prevent the occurrence of a deadlock.
B. Mutual Exclusion: Sharable resources do not require mutually exclusive access and
thus cannot be involved in a deadlock. Read-only files are a good example of a
sharable resource.
C. Hold and Wait: we must guarantee that, whenever a thread requests a resource, it
does not hold any other resources. Two protocols can be used.
1. Each thread to request and be allocated all its resources before it begins
execution.
2. Allows a thread to request resources only when it has none.
D. Disadvantages
1. Resource utilization may be low.
2. starvation is possible.
E .No Preemption: To ensure that this condition does not hold, we can use the
following protocol.
1. If a thread is holding some resources and requests another resource that cannot be
immediately allocated to it (that is, the thread must wait), then all resources the thread
is currently holding are preempted.
OR
2. If a thread requests some resources, then check if
a. Available: allocate them.
b. Not available:
1. Allocated to some other thread that is waiting for additional resources : preempt the
desired resources from the waiting thread and allocate them to the requesting thread.
2. If the resources are neither available nor held by a waiting thread, the requesting
thread must wait.
F. Circular Wait: One way to ensure that this condition never holds is to impose a total
ordering of all resource types and to require that each thread requests resources in an
increasing order of enumeration.
H. Each thread can request resources only in an increasing order of enumeration. That
is, a thread can initially request an instance of a resource—say, Ri. After that, the
thread can request an instance of resource Rj if and only if F(Rj) > F(Ri).
الوقاية من الطريق المسدود Deadlock Prevention
Disadvantages.Eسلبيات
ضا.
-1قد يكون استخدام الموارد منخف ً
-2الجوع ممكن.
No Preemptionال توجد إجراءات وقائية :للتأكد من أن هذا الشرط ال ينطبق ،يمكننا استخدام البروتوكول التالي.
-1إذا كان مؤشر الترابط يحتفظ ببعض الموارد ويطلب موردًا آخر ال يمكن تخصيصه له على الفور (أي ،يجب أن ينتظر
مؤشر الترابط) ،فإن جميع الموارد التي يحتفظ بها مؤشر الترابط حاليًا تكون ُمسبقة.
او
-2إذا طلبت سلسلة رسائل بعض الموارد ،فتحقق مما إذا كان
-1متاح :تخصيصها.
-2غير متاح:
-1مخصص لبعض سالسل الرسائل األخرى التي تنتظر موارد إضافية :استبق الموارد المطلوبة من سلسلة الرسائل
المنتظرة وقم بتخصيصها إلى سلسلة الرسائل المطلوبة.
-2في حالة عدم توفر الموارد أو عدم االحتفاظ بها بواسطة سلسلة انتظار ،يجب أن ينتظر مؤشر الترابط المطلوب
Circular Wait.Fانتظار دائري :إحدى الطرق للتأكد من عدم استمرار هذا الشرط هي فرض ترتيب إجمالي لجميع
أنواع الموارد والمطالبة بأن يطلب كل مؤشر ترابط الموارد بترتيب متزايد من التعداد.
.Hيمكن لكل مؤشر ترابط أن يطلب موارد فقط بترتيب متزايد من التعداد .وهذا يعني أن الخيط يمكن أن يطلب في البداية
مثيال لمورد — على سبيل المثال Ri. ،بعد ذلك ،يمكن أن يطلب مؤشر الترابط مثيالً للمورد Rjإذا وفقط إذا كان F
ً
(Rj)> F (Ri).
• Example: In a system if
• F (tape drive) = 1.
• F (disk drive) =5
• F (printer) = 12
• If a thread is holding a tape drive, it can request a disk drive or a printer. If it is
holding a disk drive , it can request only the printer. If it is holding a printer it can
request none of the other resources. The solution is to release the printer and request
other resources in an increasing order.
في نظام إذا:مثال
1 = ))محرك الشريطF*
5 = ))محرك األقراصF*
12 = ))طابعةF *
فيمكنه، إذا كان يحتوي على محرك أقراص. فيمكنه طلب محرك أقراص أو طابعة، *إذا كان الخيط يحمل محرك أشرطة
الحل هو تحرير الطابعة وطلب. فال يمكنها طلب أي من الموارد األخرى، إذا كانت تحتفظ بطابعة.طلب الطابعة فقط
.موارد أخرى بترتيب متزايد
Deadlock Avoidance
* Safe sequence: A sequence of threads is a safe sequence for the current allocation state if,
for each Ti, the resource requests that Ti can still make can be satisfied by the currently
available resources plus the resources held by all Tj, with
j < i.
*If no such sequence exists, then the system state is said to be unsafe
*A safe state is not a deadlocked state.
* A deadlocked state is an unsafe state.
* Not all unsafe states are deadlocks, An unsafe state may lead to a deadlock.
تجنب الجمود Deadlock Avoidance
*التسلسل اآلمن :تسلسل الخيوط هو تسلسل آمن لحالة التخصيص الحالية ،إذا كان من الممكن تلبية طلبات الموارد التي ال
يزال بإمكان Tiالقيام بها من خالل الموارد المتاحة حاليًا باإلضافة إلى الموارد التي يحتفظ بها كل ، Tjمع i>j
*في حالة عدم وجود مثل هذا التسلسل ،يقال إن حالة النظام غير آمنة
*ليست كل الدول غير اآلمنة في طريق مسدود ،فالدولة غير اآلمنة قد تؤدي إلى طريق مسدود.
Example:
consider a system with twelve resources and three threads. The maximum needs and current
needs are as shown in the table:
:مثال
الحد األقصى لالحتياجات واالحتياجات.ضع في اعتبارك نظا ًما يحتوي على اثني عشر موردًا وثالثة مؤشرات ترابط
:الحالية كما هو موضح في الجدول
5=5-10 : للوصول إلى الحد األقصى من الحاجة إلى T0
2=2-4 : للوصول إلى الحاجة القصوى لـ T1
للوصول إلى الحد األقصى من الحاجة إلى 7=2-9 : T2
9 =2+2+5 : إجمالي االحتياجات الحالية
3=9-12 : الموارد المتاحة مجانا