Using Strings as Synchronization Locks in Java
Using Strings as Synchronization Locks in Java
In Java, the String class possesses unique characteristics due to its implementation of the string constant pool. Although the implementation details changed in JDK 1.8 and later versions, the fundamental behavior remains consistent.
This distinctive feature allows us to utilize String objects as s ...
Posted on Thu, 18 Jun 2026 18:00:08 +0000 by Leppy
Fundamentals of Concurrent Programming
Root Causes of Concurrency Issues
Visibility
Visibility refers to the ability of a thread to immediately observe changes made to shared variables by other threads. The fundamental problem stems from CPU cache architectures.
// Thread A executes
int counter = 0;
counter = 42;
// Thread B executes
int result = counter;
When Thread A executes c ...
Posted on Sun, 31 May 2026 23:21:42 +0000 by fris
Multithreaded C Implementation with Regex and File I/O for Extracting Numeric Data
This article demonstrates a C program that reads a source file line by line, extracts numeric segments from each line using regular expressions, and writes the results to a target file. The implementation uses two threads that alternate execution, with a mutex protecting shared data.
The gather thread is responsible for reading lines from the s ...
Posted on Tue, 26 May 2026 18:04:04 +0000 by ionik
Cross-Clock Domain Handshake Mechanisms
When transferring data between different clock domains, handshake synchronization mechanisms provide a reliable solution. These mechanisms are categorized into half-handshake and full-handshake approachse. The half-handshake method is suitable for transferring data from a lower frequency clock domain to a higher frequency domain, as the receive ...
Posted on Wed, 20 May 2026 05:53:58 +0000 by doremi
Python Threading: Concurrency, GIL, and Synchronization
Background Knowledge
Processes
In operating systems, a program cannot run independently. Only when a program is loaded into memory and the system allocates resources to it can it execute. This executing program is called a process. The difference between a program and a process is that a program is a static collection of instructions, while a ...
Posted on Mon, 18 May 2026 00:26:51 +0000 by ThEMakeR
Common Lock Strategies and Synchronized Implementation
Common Lock Strategies
Detailed Lock Strategies
1. Pessimistic Lock vs. Optimistic Lock
Criteria: When locking, predict whether the probability of lock contention is high or low.
If the probability is predicted to be high, more work is required, and locking overhead (time, system resources) is larger → Pessimistic Lock
If the probability is pr ...
Posted on Sat, 16 May 2026 00:15:43 +0000 by elenev
Configuring Rsync for Automated Remote File Synchronization
Setting up an Rsync daemon on a server enables efficient and secure file mirroring to remote clients. This guide walks through deploying a sync service on 192.168.18.211 to replicate /root/rsync-server/ to a client's /root/rsync-local directory, leveraging CentOS 6.5's built-in rsync capabilities.
Verification and Installation
Confirm rsync is ...
Posted on Fri, 15 May 2026 21:00:30 +0000 by phpyoungdeveloper
The Pitfalls of Using Integer Objects as Lock Monitors in Java
This article delves into a common synchronization pitfall when using Integer objects as monitors in Java's synchronized blocks, particularly in concurrent scenarios.
Consider the following code simulating a ticket purchasing process with two threads:
import java.util.concurrent.TimeUnit;
public class SynchronizedTest {
public static void ...
Posted on Wed, 13 May 2026 20:59:39 +0000 by trinitywave
Java Thread Synchronization: From Intrinsic Locks to Concurrency Utilities
Thread synchronization coordinates concurrent access to shared resources, preventing race conditions and ensuring memory visibility. Java provides multiple coordination mechanisms ranging from low-level intrinsic monitors to high-level concurrency utilities.
Intrinsic Locking
Every Java object possesses an intrinsic lock (monitor). When a threa ...
Posted on Tue, 12 May 2026 18:30:17 +0000 by it2051229
Avoiding Common Pitfalls When Using Java Semaphore
A Semaphore can be used to restrict concurrent access to a shared resource. However, subtle errors in its usage can lead to unexpected behavior, such as threads becoming blocked or the semaphore's permit count becoming incorrect.
Consider a scenario where three threads attempt to acquire permits from a Semaphore initialized with a count of 2. A ...
Posted on Mon, 11 May 2026 00:20:40 +0000 by Cory94bailly