在多线程和多处理器环境中进行字符串相关操作时应用程序崩溃

发布于 2024-07-26 05:44:37 字数 553 浏览 5 评论 0原文

该应用程序是在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久夏青 2024-08-02 05:44:37

当未针对多线程环境开发或测试的应用程序突然放入多线程环境中时,这是正常的。

事实上,这是一个简单的违反假设的问题。 毫无疑问,该代码是基于一次只有一个线程执行它的假设而编写的。 如果你违反了这些假设,那么事情就不太好了。

解决方案是不要违反假设:确保一次只有一个线程可以执行代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文