]> Cypherpunks repositories - gostls13.git/commit
runtime: support preemption on windows/{386,amd64}
authorAustin Clements <austin@google.com>
Fri, 25 Oct 2019 20:17:41 +0000 (16:17 -0400)
committerAustin Clements <austin@google.com>
Wed, 20 Nov 2019 17:13:59 +0000 (17:13 +0000)
commitb89b4623eb70cbdc6b0aea43a5a826b7a26f20a7
treedbe03bd384e2b2cf0ce13dd773a8c269c08612f7
parent6fd467ee29226bf4b875921b7cb3b692c9db52ef
runtime: support preemption on windows/{386,amd64}

This implements preemptM on Windows using SuspendThead and
ResumeThread.

Unlike on POSIX platforms, preemptM on Windows happens synchronously.
This means we need a make a few other tweaks to suspendG:

1. We need to CAS the G back to _Grunning before doing the preemptM,
   or there's a good chance we'll just catch the G spinning on its
   status in the runtime, which won't be preemptible.

2. We need to rate-limit preemptM attempts. Otherwise, if the first
   attempt catches the G at a non-preemptible point, the busy loop in
   suspendG may hammer it so hard that it never makes it past that
   non-preemptible point.

Updates #10958, #24543.

Change-Id: Ie53b098811096f7e45d864afd292dc9e999ce226
Reviewed-on: https://go-review.googlesource.com/c/go/+/204340
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/runtime/os_windows.go
src/runtime/preempt.go