Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

Understanding Goroutines, Concurrency, and Scheduling in Go

If we talk about go, one of the most powerful features that go gives us is probably Go’s concurrency. But what exactly happens under the hood when we spawn goroutines? Specially on modern multi-core processors? Let’s dive deep: C…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

If we talk about go, one of the most powerful features that go gives us is probably Go’s concurrency. But what exactly happens under the hood when we spawn goroutines? Specially on modern multi-core processors? Let’s dive deep:






Concurrency vs Parallelism



Before diving into Go’s internal, let’s get this out of the way -





  • Concurrency is the ability to structure a program as independently executing tasks. These tasks may not actually run at the same time, but they are designed to make progress independently. Concurrency, along with context switching, gives us a flavor of parallelism, where it makes us think processes are running at the same time, but when in actual case, it’s just jumping between processes while saving their states in Process Control Block(PCB) or Thread Control Block (TCB). How our CPU does this, is a tale of another day.


  • Parallelism means actually executing multiple tasks simultaneously.



Go enables concurrency by default via goroutines. Whether this results in parallelism depends on our hardware and the Go runtime’s configuration via GOMAXPROCS






Goroutine



Let’s lift the lid. What exactly is a goroutine? Its a lightweight, user-managed thread of execution. But here’s the catch, this is not like OS threads. Key differences are below:




  • Extremely cheap to create (initial stack ~2KB)

  • Scheduled cooperatively by the Go runtime, not by the OS

  • Capable of scaling into the millions without overwhelming the system



When we write:




go doWork()






We’re instructing the Go scheduler to start a new goroutine that will run doWork concurrently.






Go’s Scheduler: G, M, P Model



Go uses M:N Scheduler. Many goroutines(G) are multiplexed onto a smaller number of OS threads(M), which are coordinated using logical processors(P)






Components:





  • G: Goroutine


  • M: Machine (an actual OS thread)


  • P: Processor (logical context needed to execute Go code)



Only an M with an associated P can execute go code.






High-Level Diagram








How They Work Together




  • Each P manages a local queue of runnable goroutines.

  • Each P is attached to at most one M (OS thread) at a time.

  • An M runs one goroutine (G) at a time.

  • If a goroutine blocks (e.g. on I/O), the M detaches, and the P is reassigned to another available M to continue execution.






What Happens When We Start Many Goroutines?



Suppose, we are spawning 100,000 goroutines:




for i := 0; i < 1000000; i++ {
go doWork(i)
}






On a machine with 16 logical CPUs (Logical CPUs are what we know as CPU threads - like 8 core processor has 16 threads), Go:




  • Initializes 16 Ps (by default GOMAXPROCS = 16)

  • Creates some Ms (OS threads) to execute goroutines

  • Distributes goroutines to the Ps’ local run queues



Each P runs one goroutine at a time using an M. As goroutines block or finish, the P selects the next goroutine in its queue.






Concurrency Through Context Switching






Context Switching Explained



Since the number of goroutines is often much greater than the number of available Ps or CPU threads, Go uses context switching to simulate concurrent execution.




  • When a goroutine blocks (e.g., on I/O or a channel), it is paused.

  • The scheduler saves its state (program counter, stack pointer, etc.), also known as TCB

  • The P picks another runnable goroutine and resumes it.

  • All of this is done in user space, without needing a system call, making it fast.






Single Core Example



Even with just one CPU core:




  • Only one goroutine can run at a time.

  • Go scheduler switches between goroutines, giving the illusion of concurrency.

  • This is achieved by cooperative and preemptive scheduling, context switching rapidly between runnable goroutines.






Ratios and Limits






P:M (Processor to Thread)





  • 1:1 at a time: A P is bound to one M (OS thread) at a time.

  • If an M blocks, the Go scheduler finds another idle M to attach the P to.






P:G (Processor to Goroutines)





  • 1:many: Each P maintains a queue of many runnable Gs.

  • Only one runs at a time on the P, but others wait in the queue.






M:G (Thread to Goroutines)





  • 1:1 at a time: Each M executes one goroutine at a time.

  • The M is not aware of the queue — the P hands it a goroutine to run.






Work Stealing and Global Queue



If a P’s local queue is empty, it can:





  1. Steal work from the queue of another P.


  2. Pull work from the global run queue (used as a fallback).



This ensures that all processors stay busy and that goroutines are distributed evenly across available resources.






Parallelism with Multi-Core CPUs



On a processor that has 8 cores and 16 logical cores:




  • Go sets GOMAXPROCS = 16 by default.

  • This means up to 16 goroutines can be running in true parallel at any moment — one per logical core.

  • The rest of the goroutines are scheduled cooperatively.



So Go programs benefit from both parallelism (when hardware allows) and concurrency (even when limited to one core).






Conclusion



Whether we are running Go on a Raspberry Pi or a 32-core server, the same model adapts gracefully, letting us write clean concurrent code without worrying about locks, thread pools, or race conditions (beyond correctness).



If you're curious to dig deeper, tools like runtime/trace, pprof, and go tool trace can help you visualize how goroutines behave during execution.

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - Understanding Goroutines, Concurrency, and Scheduling in Go
id: 0091d31e-760a-4436-91d6-2667440f31e4
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-27
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-27"
        description = "YARA Signature for "
    strings:
        $str = "Understanding Goroutines, Conc" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Understanding Goroutines Concurrency and")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Understanding Goroutines Concurrency and*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Understanding Goroutines Concurrency and"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

CTI Threat Relationship Graph3 Knoten / 2 Relationen
CVE / Incident Software MITRE ATT&CK CWE Weakness IoC
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Analyse für identifizierte Bedrohung auf Basis von Live-CTI (ENISA EUVD): CVSS 0.0 · EPSS 0.0% · CISA KEV: nein. Handlungsableitung aus den verlinkten Hersteller-Quellen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Understanding Goroutines, Concurrency, and Scheduling in Go

Thematisch verwandte Begriffe: Understanding, Goroutines, Concurrency, Scheduling · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100620 | Capgo CLI (npm package @capgo/cli) through 7.98.2 is affected by an ove…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag