在多线程和多处理器环境中进行字符串相关操作时应用程序崩溃
该应用程序是在VC++6.0中开发的。 当它及其依赖服务在多线程和多处理器环境中运行时,尝试某些字符串操作(例如字符串格式或字符串复制)时,依赖服务之一会崩溃。 然而,这在单处理器环境中是观察不到的,大多数情况下,调用堆栈看起来像这样
mfc42u!CFixedAlloc::Alloc+82 005b5b64 00000038 005b5b64
mfc42u!CString::AllocBuffer+3f 00000038 00000038 005b5b64
mfc42u!CString::AllocBeforeWrite+31 00000038 0a5bfdbc 005b5b64
mfc42u!CString::AssignCopy+13 00000038 057cb83f 0a5bfe90
mfc42u!CString::operator=+4b
任何人都遇到过这样的问题。
The application is developed in VC++ 6.0. When this is run in a multithreaded and multiprocessor environment along with its dependent services one of the dependent services crashes when attempting some string operations like string format or string copy. However this is not observed in a single processor environment and most often the call stack would look like this
mfc42u!CFixedAlloc::Alloc+82
005b5b64
00000038
005b5b64
mfc42u!CString::AllocBuffer+3f
00000038
00000038
005b5b64
mfc42u!CString::AllocBeforeWrite+31
00000038
0a5bfdbc
005b5b64
mfc42u!CString::AssignCopy+13
00000038
057cb83f
0a5bfe90
mfc42u!CString::operator=+4b
Anybody faced such problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当未针对多线程环境开发或测试的应用程序突然放入多线程环境中时,这是正常的。
事实上,这是一个简单的违反假设的问题。 毫无疑问,该代码是基于一次只有一个线程执行它的假设而编写的。 如果你违反了这些假设,那么事情就不太好了。
解决方案是不要违反假设:确保一次只有一个线程可以执行代码。
This is normal when an application that was not developed or tested for a multithreaded environment is suddenly placed into a multithreaded envirohment.
In fact, this is s simple matter of violating assumptions. The code was no doubt written on the assumption that only a single thread at a time would execute it. If you violate those assumptions, then things are not so good.
The solution is to not violate the assumption: make certain that only one thread at a time can execute the code.