开发者

How expensive are threads?

开发者 https://www.devze.com 2023-01-30 20:55 出处:网络
How expensive is a OS native thread ? The host OS allocates some virtual memory for a thread stack and a little bit of the kerne开发者_JS百科l memory for the thread control structures. Am I missing so

How expensive is a OS native thread ? The host OS allocates some virtual memory for a thread stack and a little bit of the kerne开发者_JS百科l 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号