Why gc's work.cycles not need to consider integer overflow?

98 views
Skip to first unread message

陶青云

unread,
Nov 11, 2020, 7:44:51 PM11/11/20
to golang-nuts
work.cycles defined as uint32.  Assuming gc happens every 2ms,  it take  
(1 << 32) / 500 / (24 * 3600) = 99 days to overflow.  it seems possible.

gcWaitOnMark use  (n > work.cycles) test,  is this a problem here? 

```
// gcWaitOnMark blocks until GC finishes the Nth mark phase. If GC has
// already completed this mark phase, it returns immediately.
func gcWaitOnMark(n uint32) {
        for {
                // Disable phase transitions.
                lock(&work.sweepWaiters.lock)
                nMarks := atomic.Load(&work.cycles)
                if gcphase != _GCmark {
                        // We've already completed this cycle's mark.
                        nMarks++
                }
                if nMarks > n {
                        // We're done.
                        unlock(&work.sweepWaiters.lock)
                        return
                }

                // Wait until sweep termination, mark, and mark
                // termination of cycle N complete.
                work.sweepWaiters.list.push(getg())
                goparkunlock(&work.sweepWaiters.lock, waitReasonWaitForGCCycle, traceEvGoBlock, 1)
        }
}
``` 

Reply all
Reply to author
Forward
0 new messages