启动多线程后出现问题
程序的Debug版本执行时弹出对话框,提示出现错误:
Debug Assertion Failed!
Program: G:\vc6\CommApp.exe
File:wincore.cpp
line:895
打开MFC\SRC\wincore.cpp,其895行为:
ASSERT((CWnd*)p == this); // must be us
紧接着有以下注释:
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
刚好我的程序里面用到了多线程,如果没有启动那个线程(注释掉相关代码),就不会弹出上述对话框,但是线程函数里面并没有用到线程函数传递的参数,只是用到了一个全局指针变量,程序是基于对话框的程序,指针指向主程序窗口即主对话框。这样用不行吗?
另外,在release版本中,启动那个线程也没有上述错误出现,应该是release版本不包括调试信息的缘故,但dubug版本出现错误而release没错说明程序还是有问题吧。
Debug Assertion Failed!
Program: G:\vc6\CommApp.exe
File:wincore.cpp
line:895
打开MFC\SRC\wincore.cpp,其895行为:
ASSERT((CWnd*)p == this); // must be us
紧接着有以下注释:
// Note: if either of the above asserts fire and you are
// writing a multithreaded application, it is likely that
// you have passed a C++ object from one thread to another
// and have used that object in a way that was not intended.
// (only simple inline wrapper functions should be used)
//
// In general, CWnd objects should be passed by HWND from
// one thread to another. The receiving thread can wrap
// the HWND with a CWnd object by using CWnd::FromHandle.
//
// It is dangerous to pass C++ objects from one thread to
// another, unless the objects are designed to be used in
// such a manner.
刚好我的程序里面用到了多线程,如果没有启动那个线程(注释掉相关代码),就不会弹出上述对话框,但是线程函数里面并没有用到线程函数传递的参数,只是用到了一个全局指针变量,程序是基于对话框的程序,指针指向主程序窗口即主对话框。这样用不行吗?
另外,在release版本中,启动那个线程也没有上述错误出现,应该是release版本不包括调试信息的缘故,但dubug版本出现错误而release没错说明程序还是有问题吧。
...全文
相关推荐
AnchorTask:锚点任务,可以解决多线程加载任务依赖的问题。常见的,例如Android启动优化,通常会进行多线程异步加载
锚任务 实现原理是使用有向无环图,常见的,例如Android启动优化,通常会进行多线程异步加载 我的CSDN博客: : 我的掘金: ://juejin.im/user/2207475076966584 github的: : 微信公众号:程序员徐公(stormjun94)知乎: : 基本使用 第一步:在moulde build.gradle配置远程依赖 implementation 'com.xj.android:anchortask:1.0.0' 最新的版本号可以看这里 具体使用文档 有向无环图的实现 0.1.0版本 0.1.0版本使用说明见,0.1.0版本实现内置了 , 1.0.0版本 ,参考了阿里 两个版本之间区别 之前的0.1.0版本配置初始依赖任务,是通过AnchorTask getDependsTaskList的方式,这种方式不太直观,1.0.0放弃了这种方式,参考
Android 多线程实现重复启动与停止的服务
主要介绍了Android 多线程实现重复启动与停止的服务的相关资料,多线程环境下为了避免死锁,一般提倡开放调用,开放调用可以避免死锁,它的代价是失去原子性,这里说明重复启动与停止的服务,需要的朋友可以参考下
Java多线程问题总结.doc
Java多线程问题总结.doc
Java使用Thread创建多线程并启动操作示例
主要介绍了Java使用Thread创建多线程并启动操作,结合实例形式分析了Java基于Thread类的多线程定义与启动简单操作技巧,需要的朋友可以参考下
易语言批量启动多线程源码
易语言批量启动多线程源码


