多线程的替代方法(在VC ++中由CWinThread插入) [英] Alternative method for MultiThreading (insted of CWinThread in VC++)

查看:144
本文介绍了多线程的替代方法(在VC ++中由CWinThread插入)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在使用 CWinThread 从网络摄像头远程流式传输视频,因此在创建和终止线程时出现错误(运行时错误).它第一次成功创建,但是当我在计时器中连续创建线程时一段时间后,我可能会遇到错误,并且退出应用程序时也会出现错误,线程无法正常终止.有人可以帮我解决这个问题吗?有没有其他方法可以代替多线程处理呢?如果没有其他方法可以帮助我我了解如何正确创建和终止线程.感谢所有人员.


问候,
RamyaRaj

HI to all,
I am using CWinThread for streaming video from webcam remotely,so while creating and terminating thread I am getting errors(RunTime Error).It is creating successfully for first time,but when I am creating thread continuosly in timer after sometime I am suppose to get error and also while exiting my application I am getting errors the thread is not terminating properly.Can anyone help me out from this problem.Is there any other way instead of multithreading.If no alternative method can anyone help me out how to create and terminate thread properly.Thanks to all in advance.


Regards,
RamyaRaj

推荐答案

您需要线程,不需要替代线程,需要替代计时器!通过计时器创建线程是一个典型的错误,尽管不是很常见.可能是,您只需要在整个运行时增加一个线程,只有使用偶数等待句柄或其他一些同步原语来限制它,以使线程保持等待状态(等待花费零CPU时间),直到获得工作.

这是主意.不幸的是,我无法提供更多细节,因为您没有共享代码或操作上的任何相关细节.

甚至不要玩没有线程的想法!
摆脱您的计时器.计时器是邪恶的.

—SA
You need thread and you don''t need alternative to thread, you need alternative to timer! Creating a thread by timer is a typical mistake, not very frequent though. Chances are, you need just one additional thread for whole run-time, only you should throttle it using even wait handle or some other synchronization primitive to keep your thread in wait state (spending zero CPU time for the wait) until it is given a job.

This is the idea. Unfortunately, I cannot give you more detail because you did not share your code or any relevant detail on your operation.

Don''t even play with the idea of going without threads!
Get rid of your timer. Timers are evil.

—SA


您需要坐下来阅读有关多线程和使用AfxBeginThread的教程.发布一些代码,我们将为您提供有关您做错了什么的建议,但您确实需要首先学习如何正确地进行多线程.
You need to sit and go through a tutorial on multithreading and using AfxBeginThread. Post a bit of code and we''ll give you some advice as to what you''re doing wrong, but you really need to learn about how to properly multithread first.


这篇关于多线程的替代方法(在VC ++中由CWinThread插入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆