• Sync: one Atomic operation


    Atomic operation Atomic operation refers to the operation that cannot be interrupted during program operation. Atomic operation is unlocked and is often directly realized by CPU instructions, while the lock is generally realized by the scheduler of the operating system, so the efficiency of atomic operation is generally higher. The supported types of atomic operations […]

  • Concurrent programming: Atomic


    Hello, everyone. I’m Xiaohei, a migrant worker who lives on the Internet. Before starting today’s content, let’s ask a question: is it thread safe to use int type for addition and subtraction? For example, is there a problem with operations such as I + +, + I, I = I + 1 in the case […]

  • Offer, come to the bowl, volatile problem Terminator


    Hello, everyone, I’m rhubarb, a programmer who can only write HelloWorld. Concurrent programming in Java is the key point of interview in major factories. Many knowledge points are obscure and difficult to understand. It often needs to be answered well in combination with practical experience. If you don’t answer well in the interview, it’s easy […]

  • Fundamentals: Java atomic components and synchronous components


    preface When using multithreaded concurrent programming, we often encounter the modification of shared variables. At this time, we can select concurrenthashmap and concurrentlinkedqueue to store data safely. However, if it only involves state modification and thread execution order, it is better to use atomic components starting with atomic or synchronous components such as reentrantlock and […]

  • Easy to understand: talk about thread safety and atomic operation in Python


    WeChat official account: Python programming time Online blog address: http://python.iswbm.com/en/latest/c01/c01_42.html In concurrent programming, if multiple threads access the same resource, we need to ensure that there will be no conflict during access and no error in data modification. This is what we often sayThread safety 。 Under what circumstances is it safe to access data? […]

  • Facebook Refactoring: abandon sass / less and welcome the era of atomized CSS


    The article is translated / polished by SSH,Original address。 Official account No.Front end from advanced to admission“, welcome to follow and add my friends to discuss. With the recent product deployment of Facebook and twitter, I think a new trend is growing slowly:Atomic CSS-in-JS。 In this article, we will see what atomic CSS (atomic CSS) […]

  • Deduction of rush purchase inventory


    #![allow(dead_code, unused_imports)] use std::{sync::{atomic::{Ordering, AtomicU64}, Arc}, thread}; #[derive(Debug)] struct Data{ num: AtomicU64 } impl Data { fn new(num: u64)-> Self{ Data{ num: AtomicU64::new(num) } } /** *Num: deducted quantity *Conn: atomic operation retry times */ fn deductions(&self, num: u64, conn: u8) -> Result<u64,u64>{ let mut old = self.num.load(Ordering::SeqCst); for _ in 0..conn{ if num > […]

  • erlang node_ Name phash conflict pit


    summary On the line, some machines are unloaded due to the conflict of node name hash value. Of the 10 machines, the number of conflicting machines reached as many as 4. Suppose the probability of hash is average. In 10 machines, the probability of no conflict is close >>> 1 – (1.0 / (2 ** […]

  • Go lock and atomic operation sharing


    [TOC] Go lock and atomic operation sharing Last time we talked about the collaborative process, let’s review: Like threads, coprocessors are a more lightweight scheduling unit Threads are implemented at the system level. The common scheduling method is time slice rotation method Coprocessing is an application software level implementation, and its principle is similar to […]

  • Deep decryption of go language sync map


    In work, we often encounter the situation of panic caused by concurrent reading and writing of map. Why panic occurs during concurrent reading and writing? Because in the case of concurrent reading and writing, the data in the map will be written disorderly, and thenGarbage in, garbage out, we might as well go straight to […]

  • Solution to atomic withdrawal problem of third-party payment platform


    In business logic, withdrawal requirements are often encountered. The realization of withdrawal is generally divided into two steps: Deduction balance Call the third-party payment interface to withdraw cash (e.g. wechat payment: enterprise payment to change) Suppose we write this (pseudo code): <?php DB::beginTransaction(); try { $member = Member::find($id); $member->money -= $withdrawMoney; $member->save(); $wechat->payment->pay($openid, $withdrawMoney); DB::commit(); […]

  • Implementation of distributed lock based on redis


    background Redis based implementation. code package xxx.trade.util; import xxx.core.exception.BizException; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import redis.clients.jedis.JedisCluster; import java.util.Collections; public class JedisUtil { private static final Logger LOGGER = LoggerFactory .getLogger(JedisUtil.class); private static JedisCluster jedisCluster; private static final String PREFIX=”xxx-callback:”; public JedisUtil() { // do nothing } public static boolean lock(String […]