الفرق بين المراجعتين ل"Ruby/Thread/thread variable get"

من موسوعة حسوب
< Ruby‏ | Thread
اذهب إلى التنقل اذهب إلى البحث
(أنشأ الصفحة ب'<noinclude>{{DISPLAYTITLE: التابع <code>thread_variable_get‎</code> الخاص بالصنف <code>Thread</code> في روبي}}</noinclude> تصنيف: Ruby...')
 
سطر 3: سطر 3:
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Method]]
 
[[تصنيف: Ruby Thread]]
 
[[تصنيف: Ruby Thread]]
يُعيد التابع <code>thread_variable_get</code> قيمة المتغير المحلي في [[Ruby/Thread|المهمة الفرعية]] (thread local variable) الذي تم تعيينه.  لاحظ أن هذه المتغيرات تختلف عن القيم محلية [[Ruby/Fiber|الألياف]] (fiber local values).  بالنسبة للقيم محلية [[Ruby/Fiber|الألياف]] (fiber local values)، يرجى الاطلاع على <code>[[Ruby/Thread/5B-5D|#[]]]</code> و <code>[[Ruby/Thread/5B-5D-3D|#[]=]]</code>.
+
يُعيد التابع <code>thread_variable_get</code> قيمة المتغير المحلي [[Ruby/Thread|للمهمة الفرعية]] (thread local variable) الذي تم تعيينه.  لاحظ أن هذه المتغيرات تختلف عن القيم محلية [[Ruby/Fiber|الألياف]] (fiber local values).  بالنسبة للقيم محلية [[Ruby/Fiber|الألياف]]، يرجى الاطلاع على المعاملين <code>[[Ruby/Thread/index operator|[]]]</code> و <code>[[Ruby/Thread/index operator-3D|[]=]]</code>.
  
تُحمل القيم محلية [[Ruby/Thread|المهمة الفرعية]] <code>[[Ruby/Thread|Thread]]</code> مع [[Ruby/Thread|المهام الفرعية]]، ولا تشمل [[Ruby/Fiber|الألياف]].  مثلا:
+
تُحمل القيم محلية [[Ruby/Thread|المهمة الفرعية]] مع [[Ruby/Thread|المهام الفرعية]]، وذلك على خلاف [[Ruby/Fiber|الألياف]].
 
 
 
 
 
 
تعاد القيمة "bar" لل[[Ruby/Thread|مهمة فرعية]] المحلية (thread local)، فيما تعاد nil لل[[Ruby/Fiber|ليف]] المحلية (fiber local).  يتم تنفيذ [[Ruby/Fiber|الليف]] في نفس المهمة الفرعية، لذلك ستكون القيم المحلية في [[Ruby/Thread|المهمة الفرعية]] متاحة.
 
 
==البنية العامة==
 
==البنية العامة==
 
<syntaxhighlight lang="ruby">thread_variable_get(key)  → obj or nil‎</syntaxhighlight>
 
<syntaxhighlight lang="ruby">thread_variable_get(key)  → obj or nil‎</syntaxhighlight>
 
==المعاملات==
 
==المعاملات==
 
===<code>key‎</code>===
 
===<code>key‎</code>===
 +
[[Ruby/String|سلسلة نصية]] أو رمز.
 +
 
==القيمة المُعادة==
 
==القيمة المُعادة==
 +
يُعيد التابع <code>thread_variable_get</code> قيمة المتغير المحلي [[Ruby/Thread|للمهمة الفرعية]] الذي تم تعيينه.
 +
 
==أمثلة==
 
==أمثلة==
مثال على استخدام التابع <code>thread_variable_get‎</code>:
+
مثال على استخدام التابع <code>thread_variable_get‎</code>:<syntaxhighlight lang="ruby">Thread.new {
<syntaxhighlight lang="ruby">Thread.new {
 
 
   Thread.current.thread_variable_set("foo", "bar") # set a thread local
 
   Thread.current.thread_variable_set("foo", "bar") # set a thread local
 
   Thread.current["foo"] = "bar"                    # set a fiber local
 
   Thread.current["foo"] = "bar"                    # set a fiber local
سطر 26: سطر 25:
 
     ]
 
     ]
 
   }.resume
 
   }.resume
}.join.value # => ['bar', nil]‎</syntaxhighlight>
+
}.join.value # => ['bar', nil]‎</syntaxhighlight>تعاد القيمة "<code>bar</code>" للمتغير المحلي في [[Ruby/Thread|المهمة فرعية]] (thread local)، فيما تعاد <code>nil</code> للمتغير محلي [[Ruby/Fiber|الليف]] (fiber local).  يتم تنفيذ [[Ruby/Fiber|الليف]] في نفس المهمة الفرعية، لذلك ستكون القيم المحلية في [[Ruby/Thread|المهمة الفرعية]] متاحة.
 +
 
 
==انظر أيضا==
 
==انظر أيضا==
* التابع <code>[[Ruby/Thread/thread_variable-3F|thread_variable?‎]]</code>: يُعيد التابع <code>thread_variable?‎</code> القيمة <code>true</code> إن كانت [[Ruby/String|السلسلة النصية]] (أو الرمز) موجودة كمتغير محلى [[Ruby/Thread|المهمة الفرعية]] (thread-local variable).
+
*التابع <code>[[Ruby/Thread/thread variable-3F|thread_variable?‎]]</code>: يُعيد التابع <code>thread_variable?‎</code> القيمة <code>true</code> إن كانت [[Ruby/String|السلسلة النصية]] (أو الرمز) موجودة كمتغير محلى [[Ruby/Thread|المهمة الفرعية]] (thread-local variable).
* التابع <code>[[Ruby/Thread/thread_variable_set|thread_variable_set]]</code>: يعين التابع <code>thread_variable_set</code> المتغيرا المحلي في [[Ruby/Thread|المهمة الفرعية]] (thread local) ذو الاسم <code>key</code> ويعطيه القيمة <code>[[Ruby/Thread/value|value]]</code> (انظر فقرة البنية العامة).  لاحظ أن هذه المتغيرات محلية في [[Ruby/Thread|المهمة الفرعية]]، وليس في [[Ruby/Fiber|الألياف]].  يرجى الاطلاع على <code>[[Ruby/Thread/thread_variable_get|#thread_variable_get]]</code> و <code>[[Ruby/Thread/5B-5D|#[]]]</code> لمزيد من المعلومات.
+
*التابع <code>[[Ruby/Thread/thread variable set|thread_variable_set]]</code>: يعين التابع <code>thread_variable_set</code> المتغيرا المحلي في [[Ruby/Thread|المهمة الفرعية]] (thread local)
 
==مصادر==
 
==مصادر==
 
*[http://ruby-doc.org/core-2.5.1/Thread.html#method-i-thread_variable_get قسم  التابع thread_variable_get‎ في الصنف Thread‎ في توثيق روبي الرسمي.]
 
*[http://ruby-doc.org/core-2.5.1/Thread.html#method-i-thread_variable_get قسم  التابع thread_variable_get‎ في الصنف Thread‎ في توثيق روبي الرسمي.]

مراجعة 13:02، 6 نوفمبر 2018

يُعيد التابع thread_variable_get قيمة المتغير المحلي للمهمة الفرعية (thread local variable) الذي تم تعيينه. لاحظ أن هذه المتغيرات تختلف عن القيم محلية الألياف (fiber local values). بالنسبة للقيم محلية الألياف، يرجى الاطلاع على المعاملين [] و ‎[]=‎.

تُحمل القيم محلية المهمة الفرعية مع المهام الفرعية، وذلك على خلاف الألياف.

البنية العامة

thread_variable_get(key)   obj or nil

المعاملات

key‎

سلسلة نصية أو رمز.

القيمة المُعادة

يُعيد التابع thread_variable_get قيمة المتغير المحلي للمهمة الفرعية الذي تم تعيينه.

أمثلة

مثال على استخدام التابع thread_variable_get‎:

Thread.new {
  Thread.current.thread_variable_set("foo", "bar") # set a thread local
  Thread.current["foo"] = "bar"                    # set a fiber local
  Fiber.new {
    Fiber.yield [
      Thread.current.thread_variable_get("foo"), # get the thread local
      Thread.current["foo"],                     # get the fiber local
    ]
  }.resume
}.join.value # => ['bar', nil]‎

تعاد القيمة "bar" للمتغير المحلي في المهمة فرعية (thread local)، فيما تعاد nil للمتغير محلي الليف (fiber local). يتم تنفيذ الليف في نفس المهمة الفرعية، لذلك ستكون القيم المحلية في المهمة الفرعية متاحة.

انظر أيضا

مصادر