This is a creation in Article, where the information may have evolved or changed.
" Sync " "sync/atomic " "Time " " Runtime "
1.runtime. Gosched () said to let the CPU to the time chip to others, the next time continue to resume execution of the goroutine, oneself is generally blocked, this is a very advanced sleep, we often encounter the question of how long to sleep, there is no need to consider, When someone else finishes, you will be notified naturally.
2.var Mutex sync. The mutex defines a mutex variable, uses atomic for the related atomic operation, and requires read access to the manipulated variable to Lock() mutex ensure exclusive access to the variable , and after the operation completes Unlock() the mutex, To ensure that the Go process does not die in the schedule, we explicitly use it for release after each operation runtime.Gosched() , and this release is generally handled automatically.
3. Record run time run start with t: = times. Now () records the start time, which is used at the end of the program. Now (). Sub (t) to get total time-consuming (1.XXXS), which is typically used in the code start of Main ()