# พื้นฐาน Goroutine (Go) > Goroutine, คีย์เวิร์ด go, sync.WaitGroup, runtime.GOMAXPROCS, goroutine leak - 20 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Go](https://sharpskill.dev/th/technologies/go/interview-questions.md) ## 1. Goroutine ใน Go คืออะไร? **คำตอบ** goroutine คือฟังก์ชันที่ทำงานพร้อมกันกับฟังก์ชันอื่น ๆ ถูกจัดการโดย Go runtime แทนที่จะเป็น OS มันเบามาก (สแตกเริ่มต้นไม่กี่ KB) เมื่อเทียบกับ OS thread (หลาย MB) Go scheduler สามารถมัลติเพล็กซ์ goroutine หลายพันหรือแม้แต่หลายล้านตัวบน OS thread จำนวนจำกัด ทำให้การทำงานพร้อมกันเข้าถึงได้ง่ายมากใน Go ## 2. จะเริ่ม goroutine ใหม่ใน Go ได้อย่างไร? **คำตอบ** คีย์เวิร์ด go ตามด้วยการเรียกฟังก์ชันจะเริ่ม goroutine ใหม่ ตัวอย่างเช่น 'go myFunction()' หรือ 'go func() { ... }()' สำหรับฟังก์ชันแบบไม่ระบุชื่อ goroutine จะทำงานทันทีแบบขนานไปกับโค้ดที่เรียก คำเตือน: ฟังก์ชัน main จะไม่รอ goroutine ที่เปิดขึ้นให้ทำงานเสร็จโดยอัตโนมัติ ## 3. ความแตกต่างหลักระหว่าง goroutine กับ OS thread คืออะไร? **คำตอบ** goroutine ใช้สแตกเริ่มต้นประมาณ 2 KB ในขณะที่ OS thread มักต้องการ 1-2 MB Go runtime จัดการ scheduling ของ goroutine ในพื้นที่ผู้ใช้ (M:N scheduling) โดยมัลติเพล็กซ์ goroutine หลายพันตัวบน OS thread เพียงไม่กี่ตัว สิ่งนี้ทำให้สามารถสร้าง goroutine ได้หลายล้านตัวโดยไม่ทำให้ระบบทำงานหนักเกินไป ต่างจาก OS thread ที่ถูกจำกัดด้วยทรัพยากร ## มีอีก 17 คำถาม - จะเกิดอะไรขึ้นถ้าโปรแกรมหลักจบลงก่อนที่ goroutine จะทำงานเสร็จ? - Go runtime จัดการการทำงานของ goroutine อย่างไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Go อื่นๆ - [พื้นฐาน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-basics.md): 25 คำถาม, Junior - [โครงสร้างข้อมูล Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-data-structures.md): 20 คำถาม, Junior - [อินเทอร์เฟซใน Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-interfaces.md): 18 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/go/interview-questions/error-handling.md): 20 คำถาม, Junior - [Channels](https://sharpskill.dev/th/technologies/go/interview-questions/channels.md): 22 คำถาม, Junior - [Go Modules](https://sharpskill.dev/th/technologies/go/interview-questions/go-modules.md): 18 คำถาม, Mid-Level - [เซิร์ฟเวอร์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-server.md): 24 คำถาม, Mid-Level - [ไคลเอนต์ HTTP](https://sharpskill.dev/th/technologies/go/interview-questions/http-client.md): 18 คำถาม, Mid-Level - [การเข้ารหัส JSON](https://sharpskill.dev/th/technologies/go/interview-questions/json-encoding.md): 20 คำถาม, Mid-Level - [Database/SQL](https://sharpskill.dev/th/technologies/go/interview-questions/database-sql.md): 22 คำถาม, Mid-Level - [แพ็กเกจ context](https://sharpskill.dev/th/technologies/go/interview-questions/context-package.md): 20 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/go/interview-questions/testing.md): 22 คำถาม, Mid-Level - [รูปแบบ Concurrency](https://sharpskill.dev/th/technologies/go/interview-questions/concurrency-patterns.md): 24 คำถาม, Mid-Level - [ไพรมิทีฟการซิงโครไนซ์](https://sharpskill.dev/th/technologies/go/interview-questions/sync-primitives.md): 22 คำถาม, Mid-Level - [เฟรมเวิร์กเว็บ Go](https://sharpskill.dev/th/technologies/go/interview-questions/go-web-frameworks.md): 20 คำถาม, Mid-Level - [การออกแบบ REST API](https://sharpskill.dev/th/technologies/go/interview-questions/rest-api-design.md): 20 คำถาม, Mid-Level - [gRPC](https://sharpskill.dev/th/technologies/go/interview-questions/grpc.md): 22 คำถาม, Mid-Level - [Reflection](https://sharpskill.dev/th/technologies/go/interview-questions/reflection.md): 20 คำถาม, Senior - [การจัดการหน่วยความจำ](https://sharpskill.dev/th/technologies/go/interview-questions/memory-management.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/go/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [Generics](https://sharpskill.dev/th/technologies/go/interview-questions/generics.md): 20 คำถาม, Senior - [Go Design Patterns](https://sharpskill.dev/th/technologies/go/interview-questions/design-patterns.md): 24 คำถาม, Senior - [Microservices](https://sharpskill.dev/th/technologies/go/interview-questions/microservices.md): 24 คำถาม, Senior - [ความปลอดภัยและการยืนยันตัวตน](https://sharpskill.dev/th/technologies/go/interview-questions/security-authentication.md): 24 คำถาม, Senior - [Docker & Containerization](https://sharpskill.dev/th/technologies/go/interview-questions/docker-containerization.md): 20 คำถาม, Senior - [Kubernetes Basics](https://sharpskill.dev/th/technologies/go/interview-questions/kubernetes-basics.md): 22 คำถาม, Senior - [Go ขั้นสูง](https://sharpskill.dev/th/technologies/go/interview-questions/advanced-go.md): 20 คำถาม, Senior - [การพัฒนา CLI](https://sharpskill.dev/th/technologies/go/interview-questions/cli-development.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/go/interview-questions/goroutines-basics