Can a golang program be compiled to run with only ONE goroutine ?

307 views
Skip to first unread message

Karolina GORNA

unread,
Sep 10, 2024, 9:54:56 AM9/10/24
to golang-nuts
Hello,

Maybe the question has already been asked, but I would be glad to have your feedback.

Can a golang program be compiled to run with only one goroutine, or at least one "OS thread" ?

I am aware of using GOMAXPROCS(1) to have only one "OS thread" or to use taskset -c 1 go build . to force having one "OS thread". These commands don't really work in practice, since with trace execution tools, I can see that many threads are used during the execution at the end.

Thank you for your help,
Karolina

Les informations contenues dans ce message électronique ainsi que celles contenues dans les documents attachés sont strictement confidentielles et sont destinées à l'usage exclusif du (des) destinataire(s) nommé(s).
Toute divulgation, distribution ou reproduction, même partielle, en est strictement interdite sauf autorisation écrite et expresse de l’émetteur.
Si vous recevez ce message par erreur, veuillez le notifier immédiatement à son émetteur par retour, et le détruire ainsi que tous les documents qui y sont attachés.

The information contained in this email and in any document enclosed is strictly confidential and is intended solely for the use of the individual or entity to which it is addressed.
Partial or total disclosure, distribution or reproduction of its contents is strictly prohibited unless expressly approved in writing by the sender.
If you have received this communication in error, please notify us immediately by responding to this email, and then delete the message and its attached files from your system.

Brian Candler

unread,
Sep 10, 2024, 10:00:53 AM9/10/24
to golang-nuts
What's your use case? Would TinyGo be sufficient for your needs?

"TinyGo code runs on a single core, in a single thread (think GOMAXPROCS=1)"

Ian Lance Taylor

unread,
Sep 10, 2024, 2:42:09 PM9/10/24
to Karolina GORNA, golang-nuts
On Tue, Sep 10, 2024 at 6:54 AM 'Karolina GORNA' via golang-nuts
<golan...@googlegroups.com> wrote:
>
> Maybe the question has already been asked, but I would be glad to have your feedback.
>
> Can a golang program be compiled to run with only one goroutine, or at least one "OS thread" ?
>
> I am aware of using GOMAXPROCS(1) to have only one "OS thread" or to use taskset -c 1 go build . to force having one "OS thread". These commands don't really work in practice, since with trace execution tools, I can see that many threads are used during the execution at the end.

For the standard Go implementation, no, this is not possible. Go is
inherently multi-threaded.

Ian

Zxilly Chou

unread,
Sep 10, 2024, 11:18:21 PM9/10/24
to golang-nuts
If you compile it to WebAssembly, it will works under the single thread model. However, there are still multi  goroutine be created, it was designed to.

Karolina GORNA

unread,
Oct 3, 2024, 10:46:15 AM10/3/24
to golang-nuts
Thank you very much, TinyGo was what I was looking for.
Reply all
Reply to author
Forward
0 new messages