List the functions that can stop or suspend the executi...
List the functions that can stop or suspend the executi...
In Go, there are several functions and mechanisms that can stop or suspend the execution of a current goroutine. Here are the primary ones:
time.Sleep()
:
Channel Operations:
sync.WaitGroup
:
WaitGroup
waits for a collection of goroutines to finish executing. The method WaitGroup.Wait()
blocks the calling goroutine until the counter inside the WaitGroup
is decremented to zero, which is typically done by other goroutines calling WaitGroup.Done()
.select
Statement with a Blocking Case:
select
statement allows a goroutine to wait on multiple communication operations. A select
blocks until one of its cases can run, then it executes that case. If none of the cases can proceed, it blocks the goroutine until one can.runtime.Gosched()
:
runtime.Goexit()
:
time.Sleep()
or channel operations, Goexit
stops the goroutine permanently. Before terminating, it runs any deferred calls in the goroutine. It is different from returning from the main function of the goroutine becau...senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào