मुझे सी ++ में एक एसईजीवी मिल रहा है कि मैं pthread_join()
पर अपने कॉल में आसानी से पुन: पेश नहीं कर सकता (यह लगभग 100,000 परीक्षण रनों में से एक में होता है) क्योंकि मेरा एप्लिकेशन बंद हो रहा है। मैंने इरनो के मूल्य की जांच की और यह शून्य है। यह Centos v4 पर चल रहा है।दुर्लभ मामलों में pthread_exit() pthread_detach() के बाद बुलाए जाने पर एसईजीवी क्यों करता है?
किस स्थिति में pthread_join()
एक एसईजीवी प्राप्त करेगा? यह किसी प्रकार की दौड़ की स्थिति हो सकती है क्योंकि यह बेहद दुर्लभ है। एक व्यक्ति सुझाव देता है कि मुझे pthread_detach() और pthread_exit() को कॉल नहीं करना चाहिए, लेकिन मुझे स्पष्ट क्यों नहीं है।
मेरी पहली कामकाजी परिकल्पना यह थी कि pthread_join()
को कहा जा रहा है जबकि pthread_exit()
अभी भी दूसरे धागे में चल रहा है और यह किसी भी तरह से एसईजीवी की ओर जाता है, लेकिन कई ने कहा है कि यह कोई मुद्दा नहीं है।
नाकाम रहने कोड आवेदन बाहर निकलने के दौरान मुख्य थ्रेड में SEGV हो रही इस तरह मोटे तौर पर लग रहा है (त्रुटि वापसी कोड के साथ संक्षिप्तता के लिए छोड़े गए जाँच):
// During application startup, this function is called to create the child thread:
return_val = pthread_create(&_threadId, &attr,
(void *(*)(void *))initialize,
(void *)this);
// Apparently this next line is the issue:
return_val = pthread_detach(_threadId);
// Later during exit the following code is executed in the main thread:
// This main thread waits for the child thread exit request to finish:
// Release condition so child thread will exit:
releaseCond(mtx(), startCond(), &startCount);
// Wait until the child thread is done exiting so we don't delete memory it is
// using while it is shutting down.
waitOnCond(mtx(), endCond(), &endCount, 0);
// The above wait completes at the point that the child thread is about
// to call pthread_exit().
// It is unspecified whether a thread that has exited but remains unjoined
// counts against {PTHREAD_THREADS_MAX}, hence we must do pthread_join() to
// avoid possibly leaking the threads we destroy.
pthread_join(_threadId, NULL); // SEGV in here!!!
बच्चे धागा जो बाहर निकलने पर शामिल हो गए की जा रही है निम्नलिखित चलाता है कोड जो जहां releaseCond()
मुख्य थ्रेड में कहा जाता है ऊपर बिंदु पर शुरू होता है:
// Wait for main thread to tell us to exit:
waitOnCond(mtx(), startCond(), &startCount);
// Tell the main thread we are done so it will do pthread_join():
releaseCond(mtx(), endCond(), &endCount);
// At this point the main thread could call pthread_join() while we
// call pthread_exit().
pthread_exit(NULL);
धागा ठीक से आने के लिए दिखाई दिया और कोई त्रुटि कोड आवेदन स्टार्टअप और thre के दौरान अपने निर्माण के दौरान तैयार किए गए विज्ञापन ने अपना कार्य सही ढंग से किया जो आवेदन से बाहर होने से लगभग पांच सेकंड पहले लिया गया।
इस दुर्लभ एसईजीवी को होने का कारण क्या हो सकता है और मैं इसके खिलाफ रक्षात्मक तरीके से प्रोग्राम कैसे कर सकता हूं। एक दावा यह है कि pthread_detach() को मेरा कॉल मुद्दा है, यदि हां, तो मेरे कोड को कैसे ठीक किया जाना चाहिए।
क्या आपने अपने pthread_join() के लिए स्थानीय दस्तावेज की जांच की है, सभी मानक अनुपालन नहीं हैं, आपको एक गैर नल पॉइंटर पास करना पड़ सकता है। –
"बाल धागा" को पता है कि उस निकास कोड को कब कॉल करना है? वह निकास कोड कैसे लागू किया जाता है? – jxh
केंद्र 4? बहुत रेट्रो लिनक्स थ्रेड या एनपीटीएल? – pilcrow