簡體   English   中英

多線程訪問違規讀取位置C ++

[英]Multithread Access violation reading location C++

我有一個C ++應用程序,它有一個主線程和一個Poco :: Timer來觸發一個使用Poco :: FileOutputStream寫入文件的回調:

FileOutputStream file("test.txt", ios::binary); <-- *Access violation reading location here*
file.write(reinterpret_cast<char *>(&data), sizeof(data));
file.close();

代碼總是在第一行失敗,這是調用堆棧:

testProject.exe!std :: ctype :: widen(char _Byte ='')第1716行+ 0xf字節C ++ testProject.exe!std :: basic_ios> :: widen(char _Byte ='')第126行C ++ testProject.exe! std :: basic_ios> :: init(std :: basic_streambuf> * _Strbuf = 0x038ef700,bool _Isstd = false)第135行+ 0xa字節C ++ testProject.exe!std :: basic_ostream> :: basic_ostream>(std :: basic_streambuf> * _Strbuf = 0x038ef700,bool _Isstd = false)第54行C ++ testProject.exe!Poco :: FileOutputStream :: FileOutputStream(const std :: basic_string,std :: allocator>&path =“c:\\ Projects \\ TestProject \\ test.txt” ,int mode = 32)第93行+ 0xa3字節C ++ testProject.exe!OPC_Server :: OnTimer(Poco :: Timer&timer = {...})行3656 + 0x13字節C ++ testProject.exe!Poco :: TimerCallback :: invoke(Poco :: Timer&timer = {...})第212行+ 0x14字節C ++ testProject.exe!Poco :: Timer :: run()第197行+ 0x19字節C ++ testProject.exe!Poco :: PooledThread :: run()第200行+ 0x15字節C ++ testProject.exe!Poco ::`anonymous namespace':: RunnableHolder :: run()第57行+ 0x17字節C ++ testProjec t.exe!Poco :: ThreadImpl :: runnableEntry(void * pThread = 0x00db6afc)第207行+ 0x20字節C ++ testProject.exe!_callthreadstartex()第348行+ 0xf字節C testProject.exe!_threadstartex(void * ptd = 0x00db6d00)Line 331 C

跟蹤到堆棧中,計時器線程似乎在讀取 xlocale內部頭中調用堆棧頂部的初始化_Byte時遇到問題

_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
    {   // widen char
        return (do_widen(_Byte)); <-- failed: Access violation reading location 
    }

ios標准頭中堆棧中的第二個條目:

_Elem __CLR_OR_THIS_CALL widen(char _Byte) const
    {   // convert _Byte to character using imbued locale
        const _Ctype& _Ctype_fac = _USE(getloc(), _Ctype);
        return (_Ctype_fac.widen(_Byte)); <-- call the top of the stack
    }

ios標准頭文件堆棧中的第三個條目:

protected:
    void __CLR_OR_THIS_CALL init(_Mysb *_Strbuf = 0,
        bool _Isstd = false)
        {   // initialize with stream buffer pointer
        _Init();    // initialize ios_base
        _Mystrbuf = _Strbuf;
        _Tiestr = 0;
        _Fillch = widen(' '); <-- call the second entry

但非常奇怪的是,在主線程上使用時,相同的代碼運行正常,沒有任何錯誤。

我需要為Poco :: Timer設置任何權限設置才能正常運行嗎? 還是我錯過了一些非常明顯的東西? 謝謝你的幫助。

編輯:----------------------

Poco版:1.7.3

平台:窗戶

事實證明,應用程序在創建計時器后立即退出,但退出並未干凈地完成,因此看起來應用程序仍在運行且計時器仍在滴答作響,而實際上某些資源已被釋放,這會導致錯誤。

MS的_tmain ()顯然比main()做了更多的事情。

對不起,它不是_tmain() ,而是調用_tmain()的 _tmainCRTStartup _tmain()退出時,運行其他清理代碼,我的項目不會以某種方式終止,應用程序仍然“ 正在運行 ”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM