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
.
精彩评论