简体   繁体   English

工作线程受CPU限制

[英]Worker Thread CPU-bound

I have a TCP/IP thread (the main thread) that is listening in a port. 我有一个正在侦听端口的TCP / IP线程(主线程)。 When a TCP/IP request comes i spawn a thread to treat the request. 当TCP / IP请求到来时,我会产生一个线程来处理该请求。 If the worker thread is CPU BOUND (imagine a loop from 1 to 1000000 that do nothing) , I cant receive another tcp/ip request.The SO doesnt give a slice time to the listening thread. 如果工作线程是CPU BOUND(想象一个从1到1000000的循环,什么也不做),我将无法收到另一个tcp / ip请求。因此,SO不会给监听线程分配时间。

How can i solve this problem? 我怎么解决这个问题? Is this a implementation problem? 这是实施问题吗? When the tcp/ip packet enters in the tcp/ip stack the SO must give a slice time to the listening thread? 当tcp / ip数据包进入tcp / ip堆栈时,SO必须给侦听线程一个时间片吗?

Thanks! 谢谢!

Use WinAPI functions SwitchToThread() or Sleep(0) in the worker thread so that it gives up its time slice to other threads/processes at the system. 在工作线程中使用WinAPI函数SwitchToThread()Sleep(0) ,以便将其时间片放弃给系统中的其他线程/进程。 Or in Delphi, use TThread.Yield . 或者在Delphi中,使用TThread.Yield

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

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