简体   繁体   English

AfxBeginThread有很多开销吗?

[英]Is there much overhead with AfxBeginThread?

How much overhead is there when AfxBeginThread does it's thing? 当AfxBeginThread做到这一点时会有多少开销?

I have an embarrassingly parallel project, and I want to launch batches of 4-15 threads with AfxBeginThread, wait for each to finish naturally, compare the results, then repeat zillions of times. 我有一个令人尴尬的并行项目,我想用AfxBeginThread启动批量的4-15个线程,等待每个线程自然完成,比较结果,然后重复数十万次。

What has me concerned is that each worker thread is going to do much less than a second's worth of work, maybe 1/50th of a second or less, and frankly I don't know how many cycles go into the voodoo AfxBeginThread does to register the new thread, set it up, enter it and exit it naturally when the function ends. 让我担心的是,每个工作线程的工作量不会超过一秒钟的工作量,可能是1/50秒或更少,坦率地说,我不知道AfxBeginThread注册的伏都教有多少个周期新线程,设置它,输入它并在函数结束时自然退出。

Any thoughts? 有什么想法吗?

As a general principle, you probably want to avoid starting and stopping threads all the time. 作为一般原则,您可能希望始终避免启动和停止线程。 Create the worker threads once , and then feed them data zillions of times. 创建一次工作线程,然后将数据提供数十亿次。 Then you don't have to worry about the thread creation and destruction overhead (which is small but nontrivial). 然后你不必担心线程创建和破坏开销(这很小但很重要)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM