मैं आयरनपीथन में साइड-इफेक्ट-फ्री (शुद्ध) लैम्ब्डा अभिव्यक्ति परिभाषित करता हूं और इसे सी # प्रतिनिधि को सौंपता हूं। जब एक से अधिक थ्रेड से एक साथ प्रतिनिधि लागू मैं प्रकार AccessViolationException, NullReferenceException और FatalEngineExecutionError के अपवाद मिलता है।सी # थ्रेड-सुरक्षित नहीं होने पर पाइथन लैम्बडा अभिव्यक्ति क्यों कॉल कर रहा है?
त्रुटि का उद्भव गैर-निर्धारक है और इसे उत्तेजित करने के लिए इसे कई मिलियन पुनरावृत्तियों का सामना करना पड़ता है, जो मुझे "दौड़ की स्थिति" कहता है। मैं इससे कैसे बच सकता हूं?
अपवाद केवल x64 (x86 क्रैश नहीं होता है) और डीबगर के बाहर प्रक्रिया चलाने पर उठाए जाते हैं। परीक्षण प्रणाली विंडोज 7, .NET Framework 4.0 और IronPython 2.7.1 पर कोर I7 (8 थ्रेड) है।
var engine = Python.CreateEngine();
double a = 1.0;
double b = 2.0;
while (true)
{
Func<double, double, double> calculate = engine.Execute("lambda a,b : a+b");
System.Threading.Tasks.Parallel.For(0, 1000, _ =>
{
for (int i = 0; i < 1000; i++) { calculate(a,b); }
});
Console.Write(".");
}
त्रुटि संदेश::
FatalExecutionEngineError was detected
Message: The runtime has encountered a fatal error. The address of the error was at 0xf807829e, on thread 0x3da0. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
अद्यतन: यहां तक कि अगर इंजन धागे की स्थानीय रूप में घोषित किया जाता है, यह कुछ समय के बाद दुर्घटनाओं:
यहाँ त्रुटि का उत्पादन करने के लिए कम से कम कोड है
var calculate = new ThreadLocal<Func<double, double, double>>(() => Python.CreateEngine().Execute("lambda a,b : a+b"));
'कई मिलियन किस लूप का पुनरावृत्ति? आंतरिक, समानांतर या जबकि? – leppie