mtchuyen / Golang-Tips

Tips in Golang programming
3 stars 2 forks source link

Concurrency #1

Open mtchuyen opened 4 years ago

mtchuyen commented 4 years ago

Ref:

Concurrent programming is one of the most interesting features Golang has to offer.

Concurrent dựa trên 2 kỹ thuật của Go:

GO routines combined with channels provide an easy way of performing independent tasks and communicating between them.

Tác dụng của concurrency

Jacob Kim:

Once you understand the syntax of goroutines and the theory behind concurrency, you feel as if you just gained a superpower.

Concurrency patterns

Concurrency patterns: các vấn đề problems hay được giải quyết (solve) bởi concurrent.

  1. Fan-In Pattern
  2. Take First n Values from Stream
  3. Subscription Pattern
  4. Map pattern
  5. Filter pattern

Ref:

Go: Concurrency Bugs in Go

https://medium.com/a-journey-with-go/go-concurrency-bugs-in-go-7d3677a1f2a2

mtchuyen commented 4 years ago

How to Implement Concurrency and Parallelism in Go

https://levelup.gitconnected.com/how-to-implement-concurrency-and-parallelism-in-go-83c9c453dd2

Basic of goroutine

https://levelup.gitconnected.com/what-is-a-goroutine-find-the-right-way-to-implement-goroutines-f6ef15d1c32b

Using Goroutines and Wait Groups for Concurrency in Golang

https://medium.com/swlh/using-goroutines-and-wait-groups-for-concurrency-in-golang-78ca7a069d28

mtchuyen commented 1 year ago

How to Broadcast Channels in Go

https://betterprogramming.pub/how-to-broadcast-messages-in-go-using-channels-b68f42bdf32e

Channels are a key component of concurrent programming in Golang. They offer a clean way to communicate between various Go routines.

However, in Go the same data can only be read once from a channel.

Broadcasting Principle

Therefore, to be able to send the same information to multiple listeners, we have two main options:

mtchuyen commented 1 year ago

5 Concurrency Patterns in GO to Enhance your next Project

https://blog.devgenius.io/5-useful-concurrency-patterns-in-golang-8dc90ad1ea61

Concurrency Patterns

When a program or an algorithm is concurrent, it means that it is designed to be decomposed into smaller parts that will be executed in independent processes in parallel.

In other words, as Rob Pike said:

Concurrency is about dealing with lots of things at once. Parallelism is about doing lots of things at once.” Concurrency: nghĩa là xử lý nhiều việc cùng lúc Parallelism: nghĩa là làm nhiều việc cùng lúc

goroutines thường được sử dụng trong Golang. Khi sử dụng goroutines thường sẽ phân làm 2 loại patter: concurrent và Synchronization

concurrent thường xử dụng các kỹ thuật:

Synchronization thường sử dụng các kỹ thuật:

Concurrency Patterns

Synchronization patterns in Go