From 04e80fb2c9e502c011d367ad36307290df07cb41 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 1 Nov 2019 16:31:57 -0700 Subject: [PATCH] runtime: don't return from netpollGenericInit until init is complete As a side-effect ensure that netpollinited only reports true when netpoll initialization is complete. Fixes #35282 Updates #35353 Change-Id: I21f08a04fcf229e0de5e6b5ad89c990426ae9b89 Reviewed-on: https://go-review.googlesource.com/c/go/+/204937 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick --- src/runtime/netpoll.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/runtime/netpoll.go b/src/runtime/netpoll.go index 939b27061e..25b1d5d49e 100644 --- a/src/runtime/netpoll.go +++ b/src/runtime/netpoll.go @@ -93,7 +93,9 @@ type pollCache struct { } var ( - netpollInited uint32 + netpollInitLock mutex + netpollInited uint32 + pollcache pollCache netpollWaiters uint32 ) @@ -104,8 +106,13 @@ func poll_runtime_pollServerInit() { } func netpollGenericInit() { - if atomic.Cas(&netpollInited, 0, 1) { - netpollinit() + if atomic.Load(&netpollInited) == 0 { + lock(&netpollInitLock) + if netpollInited == 0 { + netpollinit() + atomic.Store(&netpollInited, 1) + } + unlock(&netpollInitLock) } }