c++ - Odd behavior with std::async -


निम्नलिखित नमूना कोड पर विचार करें:

  #include & lt; future & gt; # शामिल करें & lt; सरणी & gt; # शामिल करें & lt; cassert & gt; Typedef std :: सरणी & lt; int, 5 & gt; foo_t; Foo_t * बार (foo_t और amp; foo) {वापसी और amp; foo; } Int main () {foo_t foo; ऑटो a = std :: async (बार, foo); ऑटो b = std :: async (बार, foo); जोर दें (a.get () == बी.गेट ()); वापसी 0; }   

जीसीसी 4.6.3 कोई शिकायत नहीं के साथ यह संकलित। हालांकि, ये रनटाइम में विफल रहता है:

  test: test.cpp: 15: int main (): आक्षेप `a.get () == b.get () 'विफल हुआ निरस्त (कोर डंप)   

जीसीसी 4.8.2, हालांकि, फ़ाइल को संकलित करने से मना कर दिया:

  फ़ाइल में / usr / local / include / c ++ / 4.8.2 / भविष्य: 38: 0, test.cpp से: 1: /usr/local/include/c++/4.8.2/functional: 'struct std :: _ Bind_simple & lt; std :: arrays & lt; int के तत्काल में , 5ul & gt; * (* (* std :: array & lt; int, 5ul & gt;)) (std :: arrays & lt; int, 5ul & gt; & amp;) & gt; ': /usr/local/include/c++/4.8.2/future: 1525: 70: 'std :: भविष्य & lt; typename std :: result_of & lt; _Functor (_ArgTypes ...) & gt; :: प्रकार & gt; std :: async (std :: launch, _Fn & amp;, _Args & amp; ...) [_Fn = std :: arrays & lt; int, 5ul & gt; * (& amp;) (std :: सरणी & lt; int, 5ul & gt) के साथ ; & amp;); _Args = {std :: arrays & lt; int, 5ul & gt; & amp;}; typename std :: result_of & lt; _Functor (_ArgTypes ...) & gt; :: type = std :: सरणी & lt; int, 5ul & gt; *] '/usr/local/include/c++/4.8.2/future:1541:36: 'Std :: future & lt; typename std :: result_of & lt; _Functor (_ArgTypes ...) से & gt; :: प्रकार & gt; std :: async (_Fn & amp;, _Args & amp; ...) [_Fn = std :: arrays & lt; int, 5ul & gt; * (& amp;) (std :: सरणी & lt; int, 5ul & gt; & amp;;); _Args = {std :: arrays & lt; int, 5ul & gt; & amp;}; typename std :: result_of & lt; _Functor (_ArgTypes ...) & gt; :: type = std :: सरणी & lt; int, 5ul & gt; *] 'test.cpp: 13: 30: यहां से आवश्यक है / usr / local / include / c ++ /4.8.2/functional:1697:61: त्रुटि: 'class std :: result_of & lt; std :: array & lt; int, 5ul & gt; * (* (* (* std :: सरणी & lt; int, 5ul & gt;) में' प्रकार 'नाम का कोई प्रकार नहीं है ) (स्टडी :: सरणी & lt; int, 5ul & gt; & amp;) & gt; ' Typedef typename result_of & lt; _Callable (_Args ...) & gt; :: type result_type; ^ /usr/local/include/c++/4.8.2/functional:1727:9: त्रुटि: 'क्लास std :: result_of & lt; std :: array & lt; int, 5ul & gt; * (* (std :: सरणी & lt; int, 5ul & gt;)) (std :: arrays & lt; int, 5ul & gt; & amp;) & gt; ' _M_invoke (_Index_tuple & lt; _Indices ... & gt;) ^   

यह एक libstdc ++ समस्या प्रतीत होता है।

तो मेरे सवाल हैं: 1- जीसीसी को इस कोड को अस्वीकार करना चाहिए , या मानक में कुछ है जो मुझे पता नहीं है। 2 - अभियोग विफल होना चाहिए? अपेक्षित व्यवहार यह है कि एसिंक फ़ंक्शंस जो समान संदर्भ लेते हैं, उसी ऑब्जेक्ट को देखें, लेकिन ऐसा प्रतीत होता है कि एक प्रति async कार्य में स्थानीय बनाया गया है।

मैंने क्लैग के साथ संकलन करने की कोशिश की है, लेकिन यह एक ही संकलन त्रुटि समस्याएं हैं (जैसा कि वही लिब्स्टडीसी ++ करता है) 4.8.2 के साथ है, और यह 4.6.3 पुस्तकालय हेडर को संकलित नहीं कर सकता।

  1. हां, जीसीसी को इस कोड को अस्वीकार करना चाहिए। std :: async तर्कों की नकल करता है और उन्हें रैवल्यूज़ के रूप में आगे बढ़ाता है। आप एक लावलू संदर्भ के लिए एक rvalue बाध्य नहीं कर सकते, तो यह विफल हो जाता है। यदि आप संदर्भ उपयोग से std :: ref (foo) पास करना चाहते हैं इस विशिष्ट उदाहरण में, std :: async (bar, foo) के लिए कॉल अनिवार्य रूप से निम्न करता है:

      टेम्पलेट & lt; typename F & gt; भविष्य के & lt; foo_t * & gt; एसिंक (एफ एंड फ़ंक, फू_टी एंड एजीजी) {एफ फ़नस्कोपी (फ़ेन्क); Foo_t arg_copy (आरजीआर); // पृष्ठभूमि थ्रेड पर internal_set_future_result (func_copy (std :: move (arg_copy))); वापसी ...; }    
  2. यदि आप std :: ref (foo) का उपयोग करते हैं तो दावा विफल नहीं होना चाहिए। यदि कोड संकलित नहीं करता है तो यह एक विवादास्पद बिंदु है।

Comments

Popular posts from this blog

asp.net - Procedure or function "Procedure name" expects a parameter "Param name" which was not supplied occurs rarely -

c++ - Redefined variable in the other module -

c# - The item with identity 'Id' already exists in the metadata collection. Parameter name: item -