Urgent.News

What's breaking now, across thousands of outlets.

Tech

Concurrency Programming (10): How BlockingQueue and Channels Work — From Runtime to CPU

Table of Contents 0. What Does This Article Answer Next? 1. How Does the JDK Implement ArrayBlockingQueue? 1.1 Layers 1.2 End-to-End Implementation Path for put / take 1.3 Guarantees at the Runtime / Language Implementation Layer 1.3.1 Atomicity 1.3.2 Visibility and Ordering 1.4 Guarantees at the Hardware Layer 2. How Does Go Runtime Implement Channels? 2.1 Layers 2.2 End-to-End Implementation…

The article compares the implementations of BlockingQueue, channels, and queue.Queue in Java, Go, and CPython. These data structures provide guarantees around Atomicity, Visibility, and Ordering across different layers of the runtime, standard libraries, and hardware.

At the language/library layer:

In Java, the ArrayBlockingQueue uses a lock (ReentrantLock) for atomicity, ensuring one enqueue or dequeue operation updates the queue state without interference from other threads. Visibility and ordering are maintained through the lock, making the producer's writes visible to the consumer once the lock is acquired.

In Go, channels achieve atomicity by acquiring a lock (chanlock) before updating buffer state or finding a waiting peer. Visibility is ensured by the lock's order, with writes taking effect before reads. Ordering is provided through acquire/release semantics and memory ordering constraints on the x86-64 hardware.

At the hardware layer:

Atomicity is achieved through atomic instructions like LOCK CMPXCHG, which update shared data without interference. Visibility relies on cache coherence protocols (MESIF or MOESI) to ensure updates are propagated to all caches. Ordering is managed by acquire and release memory fences, ensuring the correct sequence of read-modify-write operations.

In summary, all three implementations rely on a combination of locks, atomic instructions, cache coherence, and memory ordering to provide consistent guarantees across the runtime, standard library code, and hardware. These primitives enable thread-safe communication and synchronization, even in the presence of concurrent access.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

React Performance Debugging: Find and Fix Unnecessary Re-Renders with Real Examples

Have you ever clicked a button in a React application and noticed that components you didn't touch were rendering again? Maybe a dashboard feels sluggish when updating a counter.

  • Unnecessary re-renders cause sluggish React performance
  • Four common causes: props/state changes, parent rendering, consumed context, external subscriptions
  • Memoize unstable object references with useMemo to fix re-renders

Test Your supabase-js Code Without a Server: An In-Process Backend for Vitest

Most Supabase apps end up with one of two testing strategies: Mock supabase-js . Fast, but the mocks test what you think the database does. RLS, constraints, and defaults never run.

  • In-process backend runs within test process, no server needed
  • Uses Vitest and tinbase for JavaScript testing and Supabase compatibility
  • tinbase provides backend.fetch function for supabase-js requests

I Got Tired of “Free Tools” That Upload My Files — So I Built Browser-Only Ones

Most “free online tools” ask you to paste text or upload a photo. What they don’t always make clear: that content often leaves your device.

  • KeptTools offers browser-only developer and image tools without file uploads.
  • No account required, files deleted when tab closed, ensuring privacy.
  • Features include JSON formatting, JWT decoding, image compression, and more.

More from Thursday 15 October →