单独线程中的无限循环 [英] infinite loops in separate threads
问题描述
任何想法?
如果可能的话,只需编写所有的线程来完成在特定时间完成的最重要的事情。如果您不清楚您正在做什么,线程优先级可能导致严重的性能问题 。相反,只需对您的线程进行编码:
-
有什么重要吗?如果是这样做。
-
有什么不太重要吗?
-
转到步骤1。
说你使用线程优先级。想象一下:
-
一个低优先级的任务,A,抓住数据库的锁。
-
一个正常的优先级任务B需要大量的CPU时间,它会从低优先级的任务中窃取CPU。
-
正常优先级任务C需要访问数据库。但是它不能运行,因为低优先级任务保持对数据库的锁定,任务B使CPU超过任务A.
-
现在,任务C有等到任务B完成才能访问数据库。但是它应该与任务B相乘。
I have some data base optimization routines that need to execute periodically. I am currently using a TTimer but the main VCL freezes and is very hacky ... I would like to know what the best method is to have a low cpu consumption and execute these routines. I think putting the routines in separate threads with low thread priority is the best way.
Any ideas ?
If possible, it is much better to just code all your threads to do the most important thing that needs to get done at that particular time. Messing with thread priorities can cause serious performance problems if you don't know exactly what you're doing. Instead, just code your threads like this:
Is there anything important to do? If so do it.
Is there anything not too important to do? If so, do a little of it.
Go to step 1.
Say you do use thread priorities. Imagine this:
A low priority task, A, grabs a lock on the database.
A normal priority task, B, requires lots of CPU time, it steals the CPU from the low priority task.
A normal priority task, C, requires access to the database. But it can't run because the low priority task holds the lock on the database and task B gets the CPU over task A.
Now, task C has to wait until task B is complete to get access to the database. But it should be timeslicing with task B.
这篇关于单独线程中的无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!