Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 GO


  Deep Dive into Spin Locks in Golang

In concurrent programming, a Mutex is a commonly used synchronization mechanism to protect critical resources and prevent data races. However, in certain specific scenarios, especially when the lock-holding time is short and the number of threads is limited, a more lightweight lock known as a Spin Lock can provide higher performance.What is a Spin LockA Spin Lock is a form of busy-wait lock. When a thread attempts to acquire a lock held by another thread, it continuously checks the lock's status (i.e., "spins") until the lock is released, at which point it takes ownership. This waiting method ...

889 0       SPINLOCK MUTEX GOLANG


  Break down defer statements in GoLang

Basic ConceptsWhat are the characteristics of the deferred statement defer in Go language? When is it usually used?The deferred statement(defer statement) in Go language has the following characteristics:Deferred Execution: Deferred statements are executed before the function containing them exits, regardless of whether the function returns normally or encounters an exception.Last In, First Out (LIFO): If there are multiple deferred statements, they are executed in the order of last in, first out (LIFO). In other words, the last deferred statement is executed first, and the first deferred stat...

743 0       DEFER GOLANG


  Mastering Go Channels: How to Build Concurrent Applications Like a Pro

IntroductionIn the world of concurrent programming, Go channels have quickly become a popular tool for building fast and efficient applications. Utilizing channels can help you take full advantage of the power of Go's lightweight threads, or goroutines, and enable you to easily and effectively manage data sharing and synchronization. In this article, we'll dive deep into the world of Go channels and show you how to build concurrent applications like a pro.Understanding Go ChannelsTo start, let's take a closer look at what Go channels are and how they work. In Go, channels are a way to communic...

643 0       CONCURRENCY GOLANG CHANNEL


  Connect to SQLite using Go on Windows

In software development, it's often necessary to test and validate logic using a lightweight and easily manageable database system. SQLite, with its minimal setup and zero configuration requirements, is an excellent choice for such scenarios. Leveraging the simplicity and efficiency of SQLite for testing purposes can significantly streamline the development process. In this guide, we'll explore how to seamlessly connect to SQLite using Go on Windows, empowering developers to efficiently test their code with a reliable and straightforward database solution.Install SQLIte3 PackagesGo has built-i...

595 0       WINDOWS TUTORIAL GOLANG SQLITE3


  Understanding Slice Behavior in Go

In Go, understanding how slices behave when passed to functions is crucial for writing efficient and bug-free code. This behavior is often a source of confusion for many developers, especially those new to the language. In this article, we'll explore the difference between passing slices by value and by reference, and how it impacts the modification of slices within functions.IntroductionIn Go, slices are a fundamental data structure used to work with sequences of elements. They are essentially a view into an underlying array, providing a flexible and powerful way to manipulate collections of ...

429 0       ARRAY SLICE PASS BY REFERENCE PASS BY VALUE


  Why init() is not recommended in Go

golangci lintCurrently, the unified CI's .golangci.yml includes the gochecknoinits checker:# golangci-lint v1.46.2# https://golangci-lint.run/usage/linterslinters: disable-all: true enable: ... - gochecknoinits # Checks that no init functions are present in Go code. ref: https://github.com/leighmcculloch/gochecknoinits ...If Go code uses the init() function, the following error will occur:# golangci-lint runfoo/foo.go:3:1: don't use `init` function (gochecknoinits)func init() {^That is, it's not recommended to use init().Why not to use init()Searching "golang why not use init" on G...

399 0       GOLANG INIT() SYNC.ONCE PANIC