Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(869)

Issue 9303046: code review 9303046: runtime: detect deadlocks in programs using cgo (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 2 months ago by dvyukov
Modified:
12 years, 1 month ago
Reviewers:
iant
CC:
golang-dev, minux1, iant
Visibility:
Public.

Description

runtime: detect deadlocks in programs using cgo When cgo is used, runtime creates an additional M to handle callbacks on threads not created by Go. This effectively disabled deadlock detection, which is a right thing, because Go program can be blocked and only serve callbacks on external threads. This also disables deadlock detection under race detector, because it happens to use cgo. With this change the additional M is created lazily on first cgo call. So deadlock detector works for programs that import "C", "net" or "net/http/pprof" but do not use them in fact. Also fixes deadlock detector under race detector. It should be fine to create the M later, because C code can not call into Go before first cgo call, because C code does not know when Go initialization has completed. So a Go program need to call into C first either to create an external thread, or notify a thread created in global ctor that Go initialization has completed. Fixes issue 4973. Fixes issue 5475.

Patch Set 1 #

Patch Set 2 : diff -r ebe8bca920ad https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 3 : diff -r ebe8bca920ad https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 4 : diff -r ebe8bca920ad https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 5 : diff -r ebe8bca920ad https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 6 : diff -r ebe8bca920ad https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 7 : diff -r e05ac94ade25 https://dvyukov%40google.com@code.google.com/p/go/ #

Patch Set 8 : diff -r e05ac94ade25 https://dvyukov%40google.com@code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+16 lines, -4 lines) Patch
M src/pkg/runtime/cgo/iscgo.c View 1 2 3 4 5 1 chunk +1 line, -0 lines 0 comments Download
M src/pkg/runtime/cgocall.c View 1 2 1 chunk +4 lines, -0 lines 0 comments Download
M src/pkg/runtime/proc.c View 1 2 3 4 5 3 chunks +10 lines, -4 lines 0 comments Download
M src/pkg/runtime/runtime.h View 1 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 8
dvyukov
Hello golang-dev@googlegroups.com, I'd like you to review this change to https://dvyukov%40google.com@code.google.com/p/go/
12 years, 2 months ago (2013-05-15 11:57:55 UTC) #1
dvyukov
PTAL Added diagnostics for early cgo callbacks
12 years, 2 months ago (2013-05-15 12:27:42 UTC) #2
minux1
On Wed, May 15, 2013 at 7:57 PM, <dvyukov@google.com> wrote: > Description: > runtime: detect ...
12 years, 2 months ago (2013-05-15 12:32:50 UTC) #3
dvyukov
On Wed, May 15, 2013 at 4:32 PM, minux <minux.ma@gmail.com> wrote: > > On Wed, ...
12 years, 2 months ago (2013-05-15 12:40:41 UTC) #4
minux1
On Wed, May 15, 2013 at 8:40 PM, Dmitry Vyukov <dvyukov@google.com> wrote: > Is it ...
12 years, 2 months ago (2013-05-15 19:04:27 UTC) #5
dvyukov
On Wed, May 15, 2013 at 11:04 PM, minux <minux.ma@gmail.com> wrote: > > On Wed, ...
12 years, 2 months ago (2013-05-15 19:12:57 UTC) #6
iant
LGTM
12 years, 1 month ago (2013-05-22 18:51:23 UTC) #7
dvyukov
12 years, 1 month ago (2013-05-22 18:59:53 UTC) #8
*** Submitted as https://code.google.com/p/go/source/detail?r=ef383a4cd6bd ***

runtime: detect deadlocks in programs using cgo
When cgo is used, runtime creates an additional M to handle callbacks on threads
not created by Go.
This effectively disabled deadlock detection, which is a right thing, because Go
program can be blocked
and only serve callbacks on external threads.
This also disables deadlock detection under race detector, because it happens to
use cgo.
With this change the additional M is created lazily on first cgo call. So
deadlock detector
works for programs that import "C", "net" or "net/http/pprof" but do not use
them in fact.
Also fixes deadlock detector under race detector.
It should be fine to create the M later, because C code can not call into Go
before first cgo call,
because C code does not know when Go initialization has completed. So a Go
program need to call into C
first either to create an external thread, or notify a thread created in global
ctor that Go
initialization has completed.
Fixes issue 4973.
Fixes issue 5475.

R=golang-dev, minux.ma, iant
CC=golang-dev
https://codereview.appspot.com/9303046
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b