Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime/cgo: with -buildmode=c-archive, pprof.StartCPUProfile kills program if a non-Go thread is running #18220

Closed
bcmills opened this issue Dec 6, 2016 · 1 comment
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Dec 6, 2016

It appears that the runtime's profiling handler is not functioning correctly for non-Go threads in programs built with -buildmode=c-archive (and presumably c-shared). The following program provides a demonstration: it should exit with status 0, but instead dies with SIGPROF.

sigprof.go:

package main

import (
	"io/ioutil"
	"runtime/pprof"
)

import "C"

//export go_start_profile
func go_start_profile() {
	pprof.StartCPUProfile(ioutil.Discard)
}

//export go_stop_profile
func go_stop_profile() {
	pprof.StopCPUProfile()
}

func main() {}

sigprof.c:

#include "sigprof.h"

#include <stddef.h>
#include <time.h>

int main() {
  time_t start = time(NULL);
  go_start_profile();
  while (time(NULL) < start + 30) {};
  go_stop_profile();
  return 0;
}
$ go version
go version devel +94a4485 Tue Dec 6 22:33:48 2016 +0000 linux/amd64

$ $(go env CC) --version
clang version 3.8.0-2ubuntu3~trusty4 (tags/RELEASE_380/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ go build -buildmode=c-archive -o sigprof.a sigprof.go && $(go env CC) -o sigprof sigprof.c sigprof.a -pthread && ./sigprof
Profiling timer expired
✘
@gopherbot
Copy link

CL https://golang.org/cl/34018 mentions this issue.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.8, Go1.9 Dec 19, 2016
@golang golang locked and limited conversation to collaborators Feb 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants