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

ianlancetaylor opened this issue Jun 2, 2016 · 2 comments

runtime: main_init_done can be implemented more efficiently #15943

ianlancetaylor opened this issue Jun 2, 2016 · 2 comments


Copy link

@ianlancetaylor 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 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
Copy link

@aclements aclements commented Jun 8, 2017

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

Copy link
Contributor Author

@ianlancetaylor ianlancetaylor commented Jun 8, 2017

Bumping. Sigh.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.10, Go1.9 Jun 8, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jul 10, 2018
@aclements aclements modified the milestones: Go1.12, Go1.13 Jan 8, 2019
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.