الفرق بين المراجعتين ل"Ruby/ConditionVariable"

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
ط (مراجعة وتدقيق.)
 
(مراجعتان متوسطتان بواسطة مستخدمين اثنين آخرين غير معروضتين)
سطر 1: سطر 1:
<noinclude>{{DISPLAYTITLE: صفحة الصنف <code>ConditionVariable</code> في روبي}}</noinclude>
+
<noinclude>{{DISPLAYTITLE: الصنف <code>ConditionVariable</code> في روبي}}</noinclude>
 
[[تصنيف: Ruby]]
 
[[تصنيف: Ruby]]
 +
[[تصنيف: Ruby Class]]
 
[[تصنيف: Ruby ConditionVariable]]
 
[[تصنيف: Ruby ConditionVariable]]
ترفع كائنات الصنفِ <code>ConditionVariable</code> الصنفَ <code>[[Ruby/Mutex|Mutex]]</code>. فباستخدام المتغيرات الشرطية، من الممكن إيقاف مهمة حرجة (critical section) في أثناء تنفيذها إلى حين إتاحة مورد ما.
+
توسع كائنات الصنف <code>ConditionVariable</code> عمل الصنف <code>[[Ruby/Mutex|Mutex]]</code>. فمن الممكن باستخدام المتغيرات الشرطية إيقاف مهمة حرجة (critical section) في أثناء تنفيذها إلى حين إتاحة مورد ما.
  
إليك الأمثلة التالية:<syntaxhighlight lang="ruby">
+
إليك المثال التالي:<syntaxhighlight lang="ruby">
 
mutex = Mutex.new
 
mutex = Mutex.new
 
resource = ConditionVariable.new
 
resource = ConditionVariable.new
سطر 24: سطر 25:
  
 
</syntaxhighlight>
 
</syntaxhighlight>
 
 
==توابع الصنف العامة (Public Class Methods)==
 
==توابع الصنف العامة (Public Class Methods)==
===[[Ruby/Complex/polar|التابع <code>polar</code>]]===
+
===[[Ruby/ConditionVariable/new|<code>new</code>]]===
 
+
ينشئ نسخة جديدة من الصنف <code>ConditionVarialbe</code>.
===[[Ruby/Complex/rect|التابع <code>rect</code>]]===
+
==توابع الكائن العامة (Public Instance Methods)==
 
+
===[[Ruby/ConditionVariable/broadcast|<code>broadcast</code>]]===
===[[Ruby/Complex/rectangular|التابع <code>rectangular </code>]]===
+
يوقظ جميع المهام الفرعية (threads) التي تنتظر القفل (lock) المعيّن.
 
+
===[[Ruby/ConditionVariable/signal|<code>signal</code>]]===
 +
يوقظ أول مهمة فرعية من بين المهام الفرعية (threads) التي تنتظر القفل (lock) المعيّن.
 +
===[[Ruby/ConditionVariable/wait|<code>wait</code>]]===
 +
يحرِّر القفل المطبَّق على الكائن <code>[[Ruby/Mutex|mutex]]</code> ثم ينتظر، ثم يستعيد (reacquires) القفل عند الإستيقاظ.
 
==مصادر==
 
==مصادر==
*[http://ruby-doc.org/core-2.5.1/Complex.html قسم الصنف ConditionVariable في توثيق روبي الرسمي.]
+
*[http://ruby-doc.org/core-2.5.1/ConditionVariable.html قسم الصنف ConditionVariable في توثيق روبي الرسمي.]

المراجعة الحالية بتاريخ 12:29، 21 نوفمبر 2018

توسع كائنات الصنف ConditionVariable عمل الصنف Mutex. فمن الممكن باستخدام المتغيرات الشرطية إيقاف مهمة حرجة (critical section) في أثناء تنفيذها إلى حين إتاحة مورد ما.

إليك المثال التالي:

mutex = Mutex.new
resource = ConditionVariable.new

a = Thread.new {
   mutex.synchronize {
     # Thread 'a' now needs the resource
     resource.wait(mutex)
     # 'a' can now have the resource
   }
}

b = Thread.new {
   mutex.synchronize {
     # Thread 'b' has finished using the resource
     resource.signal
   }
}

توابع الصنف العامة (Public Class Methods)

new

ينشئ نسخة جديدة من الصنف ConditionVarialbe.

توابع الكائن العامة (Public Instance Methods)

broadcast

يوقظ جميع المهام الفرعية (threads) التي تنتظر القفل (lock) المعيّن.

signal

يوقظ أول مهمة فرعية من بين المهام الفرعية (threads) التي تنتظر القفل (lock) المعيّن.

wait

يحرِّر القفل المطبَّق على الكائن mutex ثم ينتظر، ثم يستعيد (reacquires) القفل عند الإستيقاظ.

مصادر