开发者

Worker Thread CPU-bound

开发者 https://www.devze.com 2023-02-23 04:14 出处:网络
I have a TCP/IP thread (the main thread) that is listening in a port. When a TCP/IP request comes i spawn a thread to treat the request. If the worker thread is CPU开发者_如何学Python BOUND (imagine a

I have a TCP/IP thread (the main thread) that is listening in a port. When a TCP/IP request comes i spawn a thread to treat the request. If the worker thread is CPU开发者_如何学Python 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.

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?

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. Or in Delphi, use TThread.Yield.

0

精彩评论

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