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

SEARCH KEYWORD -- Mutex



  Practice of using spinlock instead of mutex

Spinlock and mutex are two important concepts in multithreading programs. They are used to lock some shared resource to prevent concurrent access which may affect data consistency. But they do have differences, what are the differences? when should we use spinlock instead of mutex? The Theory In theory, when a thread tries to lock a mutex and it does not succeed, because the mutex is already locked, it will go to sleep, immediately allowing another thread to run. It will continue to sleep until...

   Spinlock,Mutex,Concurrency     2014-04-19 21:54:12

  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 Lock A 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 stat...

   SPINLOCK,MUTEX,GOLANG     2024-01-10 05:53:28

  What is the use of empty struct in GoLang

In Go, an empty struct struct{} is a struct with no fields that may appear to be of little use, but in reality, it can be useful in certain situations and become a simple and efficient solution in code. As a semaphore or lock Because the empty struct has no fields, it can be conveniently used to implement some concurrency control functions, such as mutex locks, read-write locks. We can use chan struct{} to implement an unbuffered channel for controlling concurrent access. package main import ( ...

   GOLANG,EMPTY STRUCT     2023-02-25 18:37:30

  Singleton Pattern in Golang

Singleton pattern is the simplest design pattern in software design. It ensures that only one instance of an object exists globally, regardless of how many times the object is instantiated. Based on the characteristics of the singleton pattern, it can be applied to scenarios such as global unique configuration, database connection objects, file access objects, etc. In Go language, there are multiple ways to implement the singleton pattern. Today, let's learn together about some of these approach...

   GOLANG,SINGLETON PATTERN,TUTORIAL     2023-08-18 23:52:05

  How does MySQL handle DROP TABLE

A few days ago, when executing DROP TABLE in MySQL, all processes including DDL and DML were hung until DROP TABLE was completed. I am confused about this phenomenon. I have reviewed the source codes of MySQL to check how MySQL internally handle DROP TABLE. When user trigger DROP TABLE command: ########################MySQL SERVER drop table######################## /* Sql_table.cc  delete (drop) tables. */bool mysql_rm_table( )   /*   Execute the drop of a normal or temporary...

   MySQL,DROP TABLE     2012-09-24 11:34:05

  Go vs C benchmark. Could Go be faster than C?

During last semester I was attending Multiprocessor Architectures course, given at Facultad de Informática where I study my Computer Science degree. As part of the assignments due to pass the course, we had to do several programs written in C to benchmark matrix multiplication by testing different techniques and technologies. First of all we had to do a secuential program in three different versions: A normal one where the result matrix is ordered by rows and the loops range the matrix by ...

   Gp,C,Benchmark,Faster,Speed,Comparison     2012-02-08 10:09:07

  Understanding GoLang interface

If goroutine and channel are considered as the foundation for GoLang concurrency, interface would be the key for data types in GoLang. In practical Go programming, almost all data types are built/used around interfaces, interface is the core of GoLang data structures. Go is not a typical OOP language, it has no class and inheritance concept syntactically. But it doesn't mean that there cannot be polymorphism in GoLang. Because of interface, it achieves the same polymorphism effect as in C++, tho...

   INTERFACE,GOLANG     2021-05-15 04:16:42

  Service discovery with etcd

In previous post, we have talked about etcd and its usage. This post we will cover how to implement server discovery with etcd. Service discovery is to solve one of the most commonly seen scenarios in distributed system where how to find the corresponding target service to talk to. In short, it is to find some server which one can talk to based on some service name. A complete service discovery system include below three key functions: Service registration: A service must register itself to so...

   ETCD,SERVICE DISCOVERY,DEMO,TUTORIAL     2021-03-08 05:36:29

  C++11 multithreading tutorial

The code for this tutorial is on GitHub: https://github.com/sol-prog/threads. In my previous tutorials I’ve presented some of the newest C++11 additions to the language: regular expressions, raw strings and lambdas. Perhaps one of the biggest change to the language is the addition of multithreading support. Before C++11, it was possible to target multicore computers using OS facilities (pthreads on Unix like systems) or libraries like OpenMP and MPI. This tutorial is meant to get you st...

   C++,Multithreading,Standard 11,Demo     2011-12-18 00:50:35

  JavaScript Needs Blocks

While reading Hacker News posts about JavaScript, I often come across the misconception that Ruby’s blocks are essentially equivalent to JavaScript’s “first class functions”. Because the ability to pass functions around, especially when you can create them anonymously, is extremely powerful, the fact that both JavaScript and Ruby have a mechanism to do so makes it natural to assume equivalence. In fact, when people talk about why Ruby’s blocks are different ...

   JavaScript,Block,Style,Format,Maintainebility     2012-01-11 11:59:35