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

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث
سطر 33: سطر 33:
  
 
==مصادر==
 
==مصادر==
*[http://ruby-doc.org/core-2.5.1/Complex.html قسم  الصنف Complex في توثيق روبي الرسمي.]
+
*[http://ruby-doc.org/core-2.5.1/Complex.html قسم  الصنف ConditionVariable في توثيق روبي الرسمي.]

مراجعة 08:43، 15 سبتمبر 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)

التابع polar

التابع rect

التابع rectangular 

مصادر