Why do we put the thread to sleep?

Usually, the use of thread::sleep allows the execution to pause for a finite amount of time as an extra protection against racing. This is not always a good plan as there isn't any real way to tell how long a thread is going to take, so it's at best a guess. As with all guesses, they can be wildly inaccurate (it is used here as we're not doing anything with the data value).

In real systems, the preferred method, to ensure that the correct amount of time is given to ensure that everything has worked is to synchronize the threads using channels.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset