Multithreading sleep and suspend problems Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiAPI/html/delphi_20061107160754287.html
Procedure tathread. Execute;
Begin
While not terminated do
Begin
Try
// Processing functions
Finally
Sleep (20 );
Self. Suspend;
End;
End;
End;
Excuse me, what is the difference between sleep and suspend? What is the specific usage? Can we still use suspend when sleep is used? How can we determine the time in sleep, in the thread processing function, I still use idudpserver to send data. Do I use synchronous control?
Let me talk about it ~~~
...
Sleep (20); // pause the thread for 20 milliseconds and run the next statement.
Self. Suspend; // pause the thread and stop running the following code.Code
...
You can see it.
Sleep is just paused, and then runs ~~~
Suspend stops the thread and does not run any more. If you want to continue running, it must be in the main thread or other purebred files,
Call thread. Resume (); to resume running;
> How to determine the time in sleep?
The sleep parameter is in milliseconds; sleep (1000); // that is, sleep 1 second;
> I still use idudpserver to send data in the thread's processing function. Do I use control synchronization?
Synchronization or not is not related to writing in the execute of the thread or writing outside the thread. It is determined by your business needs.
What's more, what's synchronization? I still don't quite understand. Please clarify your situation;
I have read an articleArticleIt is said that the thread's sleep is to let out the CPU time slice, And the thread must write the sleep, otherwise it will always occupy the CPU,ProgramThe Operation will get stuck, so I want to ask how much sleep should let out.
We have already made it very clear that the combination is unreasonable and depends on your own wishes. it depends on the specific requirements of your program. If you want to go deeper, let's take a look at this information. The CPU time slice is usually sleep (50-100.