𝔖 Scriptorium
✦   LIBER   ✦

📁

Learn Concurrent Programming with Go (Final)

✍ Scribed by James Cutajar


Publisher
Manning Publications Co.
Year
2023
Tongue
English
Leaves
392
Category
Library

⬇  Acquire This Volume

No coin nor oath required. For personal study only.

✦ Synopsis


Write concurrent code in Go that improves application performance, scales up to handle bigger loads, and takes full advantage of modern multi-processor hardware.

In Learn Concurrent Programming with Go you will learn how to:

Implement effective concurrency for more responsive, higher performing, scalable software
Avoid common concurrency problems such as deadlocks and race conditions
Manage concurrency using goroutines, mutexes, readers-writer locks, and more
Identify concurrency patterns such as pipelining, worker pools, and message passing
Discover advantages, limits and properties of parallel computing
Improve your Go coding skills with advanced multithreading

Learn Concurrent Programming with Go teaches you how to use concurrency to improve the performance of your Go applications. Each chapter poses a new problem that can be solved using concurrency and introduces the right approach to implement it in Go. In this easy-to-read tutorial, you’ll delve into concurrency patterns, learn to dodge the most common pitfalls, and take advantage of Go’s innovative approach to concurrency. Practical exercises at the end of each chapter help you practice your new skills to lock in what you’ve learned.

about the technology
Concurrent programming is essential for getting the most out of modern multi-processor computer hardware. It allows multiple tasks to execute and interact simultaneously, speeding up performance and reducing user wait time. Thanks to its baked-in concurrency models, Google’s Go is one of the best languages you can use to learn and apply concurrent programming to your systems.

about the book
Learn Concurrent Programming with Go teaches you how to boost the performance of your systems through the power of concurrent programming. It demystifies concurrency, explaining complex topics using simple language, easy-to-follow visuals, and relevant examples you’ll face every day as a developer. You’ll get an under-the-hood understanding of concurrency by building common concurrency tools like readers/writer locks, semaphores, and thread pools. By the time you’re done reading, you’ll be effortlessly coding concurrent applications in Go. You’ll also have a great foundation to apply your new concurrency skills in almost any other language.

If you have little or no experience in concurrency but have some experience in Go or a similar C-style language, this book is ideal. This book starts with a gentle introduction to concurrency concepts in the operating system and describes how Go uses them to model concurrency. We’ll then move on to explain race conditions and why they occur in some concurrent programs. Later, we’ll discuss the two main ways we can implement communication between our executions: memory sharing and message passing. In the final chapters of this book, we’ll discuss concurrency patterns, deadlocks, and some advanced topics such as spinning locks.

By the end of the book, you will be able to:
- Use concurrency to create more responsive, higher performance and scalable software.
- Recognize and avoid common concurrency programming problems such as deadlocks and race conditions.
- Employ common currency patterns in your code.
- Improve your programming skills with more advanced, multithreading topics.

This book has three parts with 12 chapters. Part 1 introduces the fundamentals of concurrent programming and communication using memory sharing:

• Chapter 1 introduces concurrent programming and talks about some of the laws governing parallel execution.
• Chapter 2 discusses the various ways we can model concurrency and the abstractions provided by operating systems and the Go runtime. The chapter also compares concurrency and parallelism.
• Chapter 3 talks about inter-thread communication using memory sharing, and it introduces race conditions.
• Chapter 4 explores different types of mutexes as solutions to some race conditions. It also shows how to implement a basic readers-writer lock.
...
• Chapter 11 illustrates how deadlock situations can develop when we have concurrency and describes various techniques for avoiding them.
• Chapter 12 deals with the internals of mutexes. It explains how mutexes are implemented in both the kernel and user space.

Who should read this book:
This book is for readers who already have some programming experience and would like to learn about concurrency. The book assumes no prior knowledge of concurrent programming. Though the ideal reader would already have some experience with Go or another C-syntax-like language, this book is also well suited for developers coming from any language—if some effort is spent learning Go’s syntax.

Concurrent programming adds another dimension to your programming: programs stop being a set of instructions executing one after the other. This makes it a challenging topic, and it requires you to think about programs in a different way. Thus, being already proficient in Go is not as important as possessing curiosity and drive. This book does not focus on explaining Go’s syntax and features but instead uses Go to demonstrate concurrency principles and techniques. Most of these techniques can be applied to other languages.

✦ Table of Contents


Inside front cover
Learn Concurrent Programming with Go
Copyright
contents
front matter
preface
acknowledgments
about this book
Who should read this book
How this book is organized: A road map
How to read the book
About the code
liveBook discussion forum
about the author
about the cover illustration
Part 1. Foundations
1 Stepping into concurrent programming
1.1 About concurrency
1.2 Interacting with a concurrent world
1.3 Increasing throughput
1.4 Improving responsiveness
1.5 Programming concurrency in Go
1.5.1 Goroutines at a glance
1.5.2 Modeling concurrency with CSP and primitives
1.5.3 Building our own concurrency tools
1.6 Scaling performance
1.6.1 Amdahl’s law
1.6.2 Gustafson’s law
Summary
2 Dealing with threads
2.1 Multiprocessing in operating systems
2.2 Abstracting concurrency with processes and threads
2.2.1 Concurrency with processes
2.2.2 Creating processes
2.2.3 Using multiprocessing for common tasks
2.2.4 Concurrency with threads
2.2.5 A multithreaded application in practice
2.2.6 Using multiple processes and threads together
2.3 What’s so special about goroutines?
2.3.1 Creating goroutines
2.3.2 Implementing goroutines in the user space
2.3.3 Scheduling goroutines
2.4 Concurrency versus parallelism
2.5 Exercises
Summary
3 Thread communication using memory sharing
3.1 Sharing memory
3.2 Memory sharing in practice
3.2.1 Sharing a variable between goroutines
3.2.2 Escape analysis
3.2.3 Updating shared variables from multiple goroutines
3.3 Race conditions
3.3.1 Stingy and Spendy: Creating a race condition
3.3.2 Yielding execution does not help with race conditions
3.3.3 Proper synchronization and communication eliminate race conditions
3.3.4 The Go race detector
3.4 Exercises
Summary
4 Synchronization with mutexes
4.1 Protecting critical sections with mutexes
4.1.1 How do we use mutexes?
4.1.2 Mutexes and sequential processing
4.1.3 Non-blocking mutex locks
4.2 Improving performance with readers–writer mutexes
4.2.1 Go’s readers–writer mutex
4.2.2 Building our own read-preferred readers–writer mutex
4.3 Exercises
Summary
5 Condition variables and semaphores
5.1 Condition variables
5.1.1 Combining mutexes with condition variables
5.1.2 Missing the signal
5.1.3 Synchronizing multiple goroutines with waits and broadcasts
5.1.4 Revisiting readers–writer locks using condition variables
5.2 Counting semaphores
5.2.1 What’s a semaphore?
5.2.2 Building a semaphore
5.2.3 Never miss a signal with semaphores
5.3 Exercises
Summary
6 Synchronizing with waitgroups and barriers
6.1 Waitgroups in Go
6.1.1 Waiting for tasks to complete with waitgroups
6.1.2 Creating a waitgroup type using semaphores
6.1.3 Changing the size of our waitgroup while waiting
6.1.4 Building a more flexible waitgroup
6.2 Barriers
6.2.1 What is a barrier?
6.2.2 Implementing a barrier in Go
6.2.3 Concurrent matrix multiplication using barriers
6.3 Exercises
Summary
Part 2. Message passing
7 Communication using message passing
7.1 Passing messages
7.1.1 Passing messages with channels
7.1.2 Buffering messages with channels
7.1.3 Assigning a direction to channels
7.1.4 Closing channels
7.1.5 Receiving function results with channels
7.2 Implementing channels
7.2.1 Creating a channel with semaphores
7.2.2 Implementing the Send() function in our channel
7.2.3 Implementing the Receive() function in our channel
7.3 Exercises
Summary
8 Selecting channels
8.1 Combining multiple channels
8.1.1 Reading from multiple channels
8.1.2 Using select for non-blocking channel operations
8.1.3 Performing concurrent computations on the default case
8.1.4 Timing out on channels
8.1.5 Writing to channels with select
8.1.6 Disabling select cases with nil channels
8.2 Choosing between message passing and memory sharing
8.2.1 Balancing code simplicity
8.2.2 Designing tightly versus loosely coupled systems
8.2.3 Optimizing memory consumption
8.2.4 Communicating efficiently
8.3 Exercises
Summary
9 Programming with channels
9.1 Communicating sequential processes
9.1.1 Avoiding interference with immutability
9.1.2 Concurrent programming with CSP
9.2 Reusing common patterns with channels
9.2.1 Quitting channels
9.2.2 Pipelining with channels and goroutines
9.2.3 Fanning in and out
9.2.4 Flushing results on close
9.2.5 Broadcasting to multiple goroutines
9.2.6 Closing channels after a condition
9.2.7 Adopting channels as first-class objects
9.3 Exercises
Summary
Part 3. More concurrency
10 Concurrency patterns
10.1 Decomposing programs
10.1.1 Task decomposition
10.1.2 Data decomposition
10.1.3 Thinking about granularity
10.2 Concurrency implementation patterns
10.2.1 Loop-level parallelism
10.2.2 The fork/join pattern
10.2.3 Using worker pools
10.2.4 Pipelining
10.2.5 Pipelining properties
10.3 Exercises
Summary
11 Avoiding deadlocks
11.1 Identifying deadlocks
11.1.1 Picturing deadlocks with resource allocation graphs
11.1.2 Deadlocking in a ledger
11.2 Dealing with deadlocks
11.2.1 Detecting deadlocks
11.2.2 Avoiding deadlocks
11.2.3 Preventing deadlocks
11.3 Deadlocking with channels
11.4 Exercises
Summary
12 Atomics, spin locks, and futexes
12.1 Lock-free synchronization with atomic variables
12.1.1 Sharing variables with atomic numbers
12.1.2 Performance penalty when using atomics
12.1.3 Counting using atomic numbers
12.2 Implementing a mutex with spin locks
12.2.1 Comparing and swapping
12.2.2 Building a mutex
12.3 Improving on spin locking
12.3.1 Locking with futexes
12.3.2 Reducing system calls
12.3.3 Go’s mutex implementation
12.4 Exercises
Summary
index
Inside back cover


📜 SIMILAR VOLUMES


Learn Concurrent Programming with Go
✍ James Cutajar 📂 Library 📅 2023 🏛 Manning 🌐 English

<span>Write concurrent code in Go that improves application performance, scales up to handle bigger loads, and takes full advantage of modern multi-processor hardware.</span><span><br><br></span><span>Learn Concurrent Programming with Go</span><span> teaches you how to boost the performance of your

Learn Concurrent Programming with Go
✍ James Cutajar 📂 Library 📅 2023 🏛 Manning 🌐 English

<span>Write concurrent code in Go that improves application performance, scales up to handle bigger loads, and takes full advantage of modern multi-processor hardware.</span><span><br><br></span><span>Learn Concurrent Programming with Go</span><span> teaches you how to boost the performance of your

Learn Concurrent Programming with Go
✍ James Cutajar 📂 Library 📅 2024 🏛 Manning 🌐 English

<span>Concurrency doesn’t need to be confusing. Start writing concurrent code that improves performance, scales up to handle large volumes of data, and takes full advantage of modern multi-processor hardware.</span><span><br><br>Too many developers think concurrency is extremely challenging. </span>

Learn Concurrent Programming with Go (ME
✍ James Cutajar 📂 Library 📅 2023 🏛 Manning Publications 🌐 English

Write concurrent code in Go that improves application performance, scales up to handle bigger loads, and takes full advantage of modern multi-processor hardware. Learn Concurrent Programming with Go teaches you how to boost the performance of your systems through the power of concurrent programming.

Learn Concurrent Programming with Go (ME
✍ James Cutajar 📂 Library 📅 2023 🏛 Manning 🌐 English

<span>Concurrency doesn’t need to be confusing. Start writing concurrent code that improves performance, scales up to handle large volumes of data, and takes full advantage of modern multi-processor hardware.</span><span><br><br>Too many developers think concurrency is extremely challenging. </span>

Go for Java Programmers: Learn the Googl
✍ Barry Feigenbaum Ph.D. 📂 Library 📅 2021 🏛 Apress 🌐 English

<p>Get an in-depth introduction to the Go programming language and its associated standard runtime libraries. This book is targeted towards programmers that already know the Java programming language and uses that Java knowledge to direct the learning of Go. You will get a deep understanding of the