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: a way to stop creating other threads #10051

Closed
moypray opened this issue Mar 2, 2015 · 6 comments
Closed

runtime: a way to stop creating other threads #10051

moypray opened this issue Mar 2, 2015 · 6 comments

Comments

@moypray
Copy link

moypray commented Mar 2, 2015

When I wrote a "hello world" program, only two line:

fmt.Println("xx")
time.Sleep(1000*time.Second)

And then go build, run the program, i found that it will create 2 more threads (3 threads in all).

I wonder if there is a way to stop creating other threads?

Actually, in linux environment, if more threads are created, we can not use unshare(CLONE_NEWUSER) syscall.

@dvyukov
Copy link
Member

dvyukov commented Mar 2, 2015

I wonder if there is a way to stop creating other threads?

No, there is no way.

can not use unshare(CLONE_NEWUSER) syscall.

Why?

@ianlancetaylor
Copy link
Member

Go programs are always multi-threaded. unshare(CLONE_NEWUSER) is defined to only work if the program is not multi-threaded. I don't see any way to call it in a Go program. You will have to write a wrapper, perhaps using the /usr/bin/unshare command.

See also #1954.

@minux
Copy link
Member

minux commented Mar 2, 2015

If you want to use unshare, one way is to call it inside a constructor
where the process is still single threaded.

/*
attribute((constructor)) void enter_ns(void) {
// call unshare here
}
*/
import "C"

@moypray
Copy link
Author

moypray commented Mar 3, 2015

@minux thanks for your reply.
And may I use flag package in this function , just like " flag.NArg()" and "flag.Arg(1)" ??

If no, how to handle argument of the program in this early phase?

@minux
Copy link
Member

minux commented Mar 3, 2015 via email

@moypray
Copy link
Author

moypray commented Mar 3, 2015

@minux thanks a lot.

@mikioh mikioh changed the title Golang thread issue runtime: a way to stop creating other threads Mar 3, 2015
@golang golang locked and limited conversation to collaborators Jun 25, 2016
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

5 participants