Multi-thread sleep and suspend Problems

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.