线程多少钱? [英] How expensive are threads?

查看:83
本文介绍了线程多少钱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OS本机线程的价格是多少?主机OS为线程堆栈分配一些虚拟内存,为线程控制结构分配少量的内核内存.我想念什么吗?

How expensive is a OS native thread ? The host OS allocates some virtual memory for a thread stack and a little bit of the kernel memory for the thread control structures. Am I missing something?

推荐答案

它可以增加调度程序的工作量,具体取决于线程的繁忙程度以及调度程序的类型.还将为堆栈的第一页分配物理内存.

It can increase the scheduler workload, depending how busy the thread is, and the kind of scheduler. It will also allocate physical memory for the first page of the stack.

在许多情况下,主要成本是缓存污染.有太多活动的并发任务会降低性能,因为太多的线程共享的缓存太少,而且它们只会不断地将彼此推回主内存,这比让线程简单地进入睡眠状态要使线程遭受痛苦要糟糕得多,因为它们一直处于睡眠状态这样会产生数百个周期的代价,而检索主内存会在单个时间片内多次产生类似的开销,并且还意味着要按比例进行更多的上下文切换,因为在该时间片内完成的工作要少得多.

The main cost in many cases is cache pollution. Having too many active concurrent tasks kills performance because too many threads are sharing too little cache, and they just keep shoving each other back onto main memory, which is a far worse indignity for a thread to suffer than simply being put to sleep, since sleeping incurs a single penalty of several hundred cycles, while retrieving main memory incurs a similar overhead several times during a single time-slice, and also means proportionally more context-switching since much less work gets done during that time-slice.

这篇关于线程多少钱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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