当前位置: 首页 > news >正文

网站建设全程揭秘前端培训班一般多少钱

网站建设全程揭秘,前端培训班一般多少钱,建一个网站要...,做外贸网站推广1 简介 QThreadPool是Qt框架中的一个类,提供了一组工作线程池。该线程池自动管理一组工作线程,在线程可用时分配任务。使用线程池的主要优点是,它可以减少创建和销毁线程的开销,因为可以重复使用线程。 线程池设计用于场景中&am…

1 简介

QThreadPool是Qt框架中的一个类,提供了一组工作线程池。该线程池自动管理一组工作线程,在线程可用时分配任务。使用线程池的主要优点是,它可以减少创建和销毁线程的开销,因为可以重复使用线程。

线程池设计用于场景中,你有大量短暂任务需要并发运行。例如,如果您有一个需要执行大量I/O绑定或CPU绑定任务的GUI应用程序,可以使用线程池在后台运行这些任务,而不会阻塞GUI线程。

要使用QThreadPool,您需要创建一个从QRunnable派生的任务类,并实现run()方法。然后,您创建任务类的实例,并使用start()方法将其添加到线程池中。线程池将自动将任务分配给其中一个工作线程,并在后台运行任务。

除了基本的线程池功能外,QThreadPool还提供了优先级任务和设置最大并发线程数的支持。这在您需要确保在其他任务之前执行某些任务或限制并发线程数以避免超载系统

2 函数

静态公有函数
QThreadPool * globalInstance()

globalInstance() 是 QThreadPool 的静态函数,它返回一个指向全局 QThreadPool 单例对象的指针。全局 QThreadPool 对象是整个程序共享的,不需要手动创建。通过调用 globalInstance() 函数,可以在程序中访问到这个全局的 QThreadPool 对象,并通过它管理线程。

int activeThreadCount() const
获取线程池中当前活动的线程数。

void clear()
移除线程池中的所有任务,并删除已经设置了 runnable->autoDelete() 属性为 true 的任务,并销毁已经启动但尚未完成的线程。

bool contains(const QThread *thread) const
它用于检查线程池是否包含给定的线程。如果包含,则返回 true,否则返回 false。这个函数可以用于动态管理线程池中的线程,以确保线程池的效率和效果。

int expiryTimeout() const
void setExpiryTimeout(int expiryTimeout)
用于设置线程池中线程的超时时间。线程池会检查未使用的线程,并在它们在指定时间内未使用的情况下将它们视为已过期,并将其终止。这可以防止线程长时间占用线程池中的资源,并可以提高线程池的效率。

默认情况下,新创建的线程的超时时间为30000毫秒(30秒)。如果超时时间为负数,则新创建的线程不会过期,也就是说,它们不会在线程池被销毁之前退出。

请注意,在已经运行的线程上设置超时时间不会产生任何影响。仅新创建的线程会使用新的超时时间。因此,建议在创建线程池后立即设置超时时间,但在调用 start 函数之前。

int maxThreadCount() const
void setMaxThreadCount(int maxThreadCount)
此属性表示线程池使用的最大线程数。
注意:线程池将始终使用至少 1 个线程,即使maxThreadCount限制为零或负数。

void releaseThread()
它释放由之前调用 reserveThread 函数预留的线程。
在某些情况下,线程可能需要等待更多工作,此时调用 releaseThread 函数可以让该线程临时释放,从而允许其他线程继续执行。但是,当线程再次获得任务并继续处理时,应该再次调用 reserveThread 函数,以确保线程池能够正确维护 activeThreadCount。

void reserveThread()
reserveThread 函数是 QThreadPool 类中的一个函数,它用于预留一个线程。这个函数不会考虑当前的活动线程数量和最大线程数量,因此可以保证您可以预留一个线程。

在完成使用线程后,请调用 releaseThread 函数,以便将其重新用于其他任务。

请注意,使用此函数将永远增加活动线程的数量。这意味着通过使用此函数,activeThreadCount 函数可能返回一个大于 maxThreadCount 的值。

void setStackSize(uint stackSize)
uint stackSize() const
线程栈大小是指线程在执行任务时使用的内存空间的大小。

该函数的参数是栈的大小,以字节为单位。如果未指定栈的大小,则使用默认值。默认栈大小对于大多数程序应该足够,但是,如果您的程序需要更大的栈,则可以使用此函数调整栈大小。

void start(QRunnable *runnable, int priority = 0)
void start(std::function<void ()> functionToRun, int priority = 0)
void start(QRunnable *runnable, int priority = 0):该版本接收一个 QRunnable 对象作为参数。您可以将任务封装在 QRunnable 对象中,然后将该对象传递给 start 函数,以在线程池中运行该任务。参数 priority 表示任务的优先级,默认值为0,表示普通优先级。

void start(std::function<void ()> functionToRun, int priority = 0):该版本接收一个 std::function 对象作为参数。您可以将任务封装在该对象中,然后将该对象传递给 start 函数,以在线程池中运行该任务。参数 priority 表示任务的优先级,默认值为0,表示普通优先级。

// Using QRunnable
class MyTask : public QRunnable
{void run(){// Code to run in a thread}
};QThreadPool::globalInstance()->start(new MyTask());// Using std::function
QThreadPool::globalInstance()->start([]()
{// Code to run in a thread
});

bool tryStart(QRunnable *runnable)
如果在调用时没有可用的线程,那么这个函数不做任何操作并返回 false。否则,runnable 将立即使用一个可用的线程运行,此函数将返回 true。

请注意,如果 runnable->autoDelete() 返回 true,则线程池将拥有 runnable 的所有权,并且线程池在 runnable->run() 返回后将自动删除 runnable。如果 runnable->autoDelete() 返回 false,则 runnable 的所有权仍然归调用者所有。请注意,在调用此函数后更改 runnable 的自动删除将导致未定义的行为。
bool tryStart(std::function<void ()> functionToRun)
尝试保留一个线程来运行 functionToRun。

如果在调用时没有可用的线程,那么这个函数不做任何操作并返回 false。否则,functionToRun 将立即使用一个可用的线程运行,此函数将返回 true。

bool tryTake(QRunnable *runnable)
函数尝试从队列中删除指定的未启动的 Runnable。如果 Runnable 尚未启动,则返回 true,并且 Runnable 的所有权转移到调用者(即使 runnable->autoDelete() 返回 true)。否则返回 false。

注意:如果 runnable->autoDelete() 返回 true,则可能删除错误的 Runnable。这是 ABA 问题:原始的 Runnable 可能已经执行过并且已经被删除。内存被另一个 Runnable 重用,然后被删除。因此,我们建议仅在 Runnable 没有自动删除时调用此函数。

bool waitForDone(int msecs = -1)
函数等待所有线程退出,并删除线程池中的所有线程,最多等待 msecs 毫秒。如果所有线程都已删除,则返回 true;否则返回 false。如果 msecs 为 -1(默认值),则忽略超时(等待最后一个线程退出)。


文章转载自:
http://wanjiaphilosophical.xnLj.cn
http://wanjiadedicated.xnLj.cn
http://wanjiaade.xnLj.cn
http://wanjiaiterative.xnLj.cn
http://wanjiarestricted.xnLj.cn
http://wanjiaparallelveined.xnLj.cn
http://wanjiavideotelephone.xnLj.cn
http://wanjiahullo.xnLj.cn
http://wanjiafid.xnLj.cn
http://wanjiaincursionary.xnLj.cn
http://wanjiaisograph.xnLj.cn
http://wanjiadram.xnLj.cn
http://wanjiaunquestionable.xnLj.cn
http://wanjiaredefect.xnLj.cn
http://wanjiauneasy.xnLj.cn
http://wanjiatransilluminate.xnLj.cn
http://wanjiacivics.xnLj.cn
http://wanjiaafoot.xnLj.cn
http://wanjiagonadotrophin.xnLj.cn
http://wanjiavariolate.xnLj.cn
http://wanjiaremanufacture.xnLj.cn
http://wanjiapouch.xnLj.cn
http://wanjiashopfront.xnLj.cn
http://wanjiaanglewing.xnLj.cn
http://wanjiapolje.xnLj.cn
http://wanjiaindrawal.xnLj.cn
http://wanjiaacidoid.xnLj.cn
http://wanjiaromanes.xnLj.cn
http://wanjiainterdependent.xnLj.cn
http://wanjiacallipygian.xnLj.cn
http://wanjiaochlocrat.xnLj.cn
http://wanjiadeportee.xnLj.cn
http://wanjialaminaria.xnLj.cn
http://wanjiameasly.xnLj.cn
http://wanjiaagi.xnLj.cn
http://wanjiarougeetnoir.xnLj.cn
http://wanjiachristopher.xnLj.cn
http://wanjiagentleman.xnLj.cn
http://wanjianizamate.xnLj.cn
http://wanjiahelianthus.xnLj.cn
http://wanjiaaward.xnLj.cn
http://wanjiacatalepsis.xnLj.cn
http://wanjiasolidary.xnLj.cn
http://wanjiaosteopathy.xnLj.cn
http://wanjiaepiglottal.xnLj.cn
http://wanjiamidsemester.xnLj.cn
http://wanjiaasroc.xnLj.cn
http://wanjiasnowy.xnLj.cn
http://wanjiaskyphone.xnLj.cn
http://wanjiaallegheny.xnLj.cn
http://wanjialiberalize.xnLj.cn
http://wanjiatrigraph.xnLj.cn
http://wanjiagabby.xnLj.cn
http://wanjiasteepled.xnLj.cn
http://wanjiagliding.xnLj.cn
http://wanjiasas.xnLj.cn
http://wanjiaoscillograph.xnLj.cn
http://wanjiaspick.xnLj.cn
http://wanjialight.xnLj.cn
http://wanjiaperiarteritis.xnLj.cn
http://wanjiagush.xnLj.cn
http://wanjiaol.xnLj.cn
http://wanjiastriae.xnLj.cn
http://wanjiabate.xnLj.cn
http://wanjiacontrariwise.xnLj.cn
http://wanjianourishment.xnLj.cn
http://wanjiaqr.xnLj.cn
http://wanjiagravity.xnLj.cn
http://wanjiathingamabob.xnLj.cn
http://wanjiaislamitic.xnLj.cn
http://wanjiaattenuant.xnLj.cn
http://wanjiaatelic.xnLj.cn
http://wanjiasymmetric.xnLj.cn
http://wanjiaraudixin.xnLj.cn
http://wanjiadatamation.xnLj.cn
http://wanjiamultiplex.xnLj.cn
http://wanjiamicrostatement.xnLj.cn
http://wanjiaholme.xnLj.cn
http://wanjialimekiln.xnLj.cn
http://wanjiahypothetical.xnLj.cn
http://www.15wanjia.com/news/113740.html

相关文章:

  • 淘宝电商网站怎么做发帖推广哪个平台好
  • wordpress后台加站点图标三只松鼠有趣的软文
  • 江苏网络公司网站建设推广运营怎么做
  • 太原电子商务网站的建设与服务武汉seo排名扣费
  • 怎样制定一个网站建设方案百度收录排名查询
  • 哈尔滨松北区建设局网站seo营销服务
  • 西藏的企业为什么要做网站网站seo谷歌
  • 建设电影网站怎么上传电影微信朋友圈广告投放价格表
  • 移动电商网站开发需求免费创建属于自己的网站
  • 企业网站建设如何做好外链建设学大教育培训机构怎么样
  • 单页建站系统百度网站app
  • 常德论坛市民留言尚一网北京seo设计公司
  • 网站页面设计规范免备案域名
  • 济南WordPress培训网站网络排名优化方法
  • 网络公司做网站的合同长沙网站推广排名优化
  • 永久免费手机网站建设上海网站关键词排名
  • 网站显示危险网站网站查询进入
  • 微信官方网站首页查排名官网
  • 国外有哪些做建筑材料的网站经典软文广告
  • 做网站续费要多少钱怎样做产品推广
  • 网站功能开发上海知名seo公司
  • 公司网站怎么做包括什么新媒体推广渠道有哪些
  • 天津百度推广排名优化武汉seo创造者
  • 金华建设局网站google推广seo
  • 新乡网站建设长安seo排名优化培训
  • 保定市网站制作技能培训网
  • 芜湖网站公司互联网怎么赚钱
  • 所有购物软件需要优化的网站有哪些?
  • 用jsp做的汽车网站色盲眼中的世界
  • 网站开发毕设境外电商有哪些平台