#Golang-Concurrent
18 articles
Creating a Thumbnail Image Generator Using Pipeline Pattern
We also use Generate Image using Golang to make it easier for editors so they don’t need to edit using other applications so that we can easily put the desired image. Now santekno will try to create a Thumbnail Image generator that already exists in this tutorial. Suppose we want to make this thumbnail image more concise than the original image. Then we need to convert it into a lighter file with a small size. What if there are many images, then if we use the usual Golang sequencial, it will be long when we execute it. So, we will try to compare how the process of generating this Thumbnail image with sequential golang using concurrent Pipeline Patter.
Creating a Web Crawler using Golang
Web Crawlers are often used to retrieve something on a website so that we get the content we need. This is usually used for content needs. In this case we will try to use Golang to create a simple Web Crawler and will retrieve some content such as URLs on a website page.
Recognizing Package Context With Timeout In Golang
Package introduction context.WithTimeout
In the previous article we learned context.WithCancel where we manually send the cancel signal from context. But we can also add cancel signal to context automatically by using timeout timings. By using timeout, we no longer need to manually call cancel execution, but with timeout cancel will be automatically executed if the timeout time has passed.
Knowing and Implementing Atomic Sync in Golang
Introduction to sync.Atomic
For atomic operations on variables in golang, the sync/atomic package offers certain low-level methods. In Go, these methods allow multiple goroutines to safely modify shared variables without using locks or other explicit synchronization. Functions like AddInt64
, AddUint32
, CompareAndSwapInt32
, etc. used to perform basic arithmetic on different types of variables can be found in the atom
package. The AddInt64
method for example, guarantees that modifications made by other goroutines will be seen when adding a certain value to an int64
variable in atomic style.
Getting to Know Sync Cond on Golang
Introduction of sync.Cond
sync.Cond
is a locking process that is used with certain conditions. sync.Cond
in the Golang synchronization package implements conditional variables that can be used in scenarios where multiple readers
are waiting for concurrent resources. Cond pooling point: multiple goroutines waiting, 1 goroutine notification event occurs. Each Cond is associated with a Lock
**(sync.Mutex or sync.RWMutex) that should be added when modifying the condition or calling the wait()
method, to protect the condition.
Getting to Know Sync Once On Golang
Introduction of sync.Once
We can use this feature in Golang to ensure that a function is executed only once. Sometimes if we already have many goroutines that are accessing, then with sync.Once
we can make sure that only the goroutine that has the first access can execute the function. So if there are other goroutines that are running, they will not execute and ignore the function.
Getting to Know Sync Map on Golang
Introduction to sync.Map
This sync.Map
is actually very similar to the regular Generic Golangnya map
, but the difference is that this map
is safe to use during concurrent goroutines.
Getting to know the Sync Pool on Golang
Introduction to sync.Pool
We often hear sync.Pool when implementing a design pattern called Object Pool Pattern. A Pool is a temporary set of objects that can be stored and retrieved individually. A Pool is safe to be used by multiple goroutines simultaneously.
Getting to Know WaitGroup on Golang
Introduction
Waitgroup is a feature of Golang that is used to wait for a process carried out by several goroutines. This is done because we need to do the process simultaneously but when we continue the next process we need data from the previous result so we have to wait first from the previous process to get the data.
Knowing Deadlock and How to Overcome It in Golang
Introduction
One of the problems that occurs when using concurrent
or parallel
is the deadlock
system. What is deadlock? Deadlock is an event where a concurrent process or goroutine waits for each other (lock) so that none of the goroutines can run. So be careful if you create an application or program that implements mutex lock and unlock using goroutines. Well we will try directly how to simulate the golang program when there is a deadlock
.
How to Create RW Mutex and Its Use in Golang
Introduction to Sync.RWMutex
After we have learned
Introduction and Creation of `Mutex` in the previous post, then we will continue to the next stage which is the introduction of RWMutex
. Now what is the difference with the previous one?
How to Create Mutex and Its Use in Golang
Introduction of Sync.Mutex
Mutex or stands for Mutual Exclusion is a way to overcome race conditions in the Golang language. Mutex can be used to do locking
and unlocking
of a mutex so that if it is locked
it will not be able to do locking
again until we do unlocking
.