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: main_init_done can be implemented more efficiently #15943

Open
ianlancetaylor opened this Issue Jun 2, 2016 · 2 comments

Comments

Projects
None yet
4 participants
@ianlancetaylor
Contributor

ianlancetaylor commented Jun 2, 2016

A C thread in a -buildmode={c-archive,c-shared} may call back into Go code before Go initialization is complete, in which case it must wait. It currently waits using a channel called main_init_done. In the review of https://golang.org/cl/23610 Dmitry points out that this can be done more efficiently. The callback will necessarily go through runtime·needm. We can arrange for needm to wait for initialization to be complete. It already waits for a new M to be created.

In fact, needm already has a race condition. It crashes if cgoHasExtraM is not true. That global variable is set to true early in Go initialization, but that initialization will be running in a separate thread. If a C thread is fast enough in calling Go, the program will crash because Go initialization has not yet reached the required point. We should avoid crashing if islibrary || isarchive; we should simply wait.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jun 2, 2016

@ianlancetaylor ianlancetaylor self-assigned this Jun 2, 2016

@quentinmit quentinmit added the NeedsFix label Oct 11, 2016

@rsc rsc modified the milestones: Go1.9, Go1.8 Nov 11, 2016

@aclements

This comment has been minimized.

Member

aclements commented Jun 8, 2017

Ping @ianlancetaylor. Should this bump to Go1.10?

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Jun 8, 2017

Bumping. Sigh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment