Tagged articles
thread::sleep
16 articles · Page 1 of 1
On Linux, a call to std::thread::sleep(Duration::from_micros(2)) typically pauses for about 60 µs—30× longer than requested—because the API only guarantees a lower bound and adds a default timer_slack of 50 µs; the article explains the kernel path, shows benchmark data, and provides practical ways to shrink the floor to ~10 µs or achieve sub‑µs latency with busy‑spin and full system tuning.
LinuxRustbusy-spin
0 likes · 21 min read

This article explores the puzzling "prevent gc" comment in RocketMQ source code, explains how Thread.sleep(0) interacts with JVM safepoints, distinguishes counted and uncounted loops, and demonstrates practical experiments that reveal why altering loop variables can change GC behavior.
GCJVMJava
0 likes · 12 min read


ITPUBDec 30, 2024 · Fundamentals
The article investigates a mysterious "prevent gc" comment in RocketMQ's source, explains how Thread.sleep(0) forces a JVM safepoint to mitigate long GC pauses, and demonstrates that changing loop counters from int to long eliminates the need for the hack.
Counted LoopGCJVM
0 likes · 22 min read

This article investigates the mysterious "prevent gc" comment in RocketMQ source code, explains how Thread.sleep(0) interacts with JVM safepoints and counted loops, and demonstrates practical fixes by changing loop indices or inserting explicit safepoint calls.
GCJavaRocketMQ
0 likes · 13 min read

This article explains how Java's Thread.sleep(0) works, its native implementation, why it is used in RocketMQ source code, and how the call influences JVM garbage‑collection, safe‑point insertion, and CPU scheduling to improve multithreaded performance.
JVMJavaRocketMQ
0 likes · 13 min read

Thread.Sleep pauses a thread for a specified time, but its behavior depends on OS scheduling; Sleep(0) yields the CPU to let other threads run, while Sleep(1000) doesn’t guarantee immediate wake‑up, illustrating how time‑slice and priority‑based scheduling affect thread execution.
C++CPU schedulingPreemptive Multitasking
0 likes · 10 min read

This article examines a puzzling 'prevent gc' comment in RocketMQ source, explains how inserting Thread.sleep(0) creates a JVM safepoint to avoid long GC pauses, explores counted vs uncounted loops, and demonstrates practical code modifications to improve performance.
JVMJava performanceRocketMQ
0 likes · 13 min read

This article investigates the mysterious Thread.sleep(0) call found in RocketMQ source, explaining how it interacts with JVM safepoints, why it appears in counted loops, and how changing loop indices from int to long can avoid long stop‑the‑world pauses, backed by code examples and references.
JVMJavaRocketMQ
0 likes · 12 min read

This article explains how Thread.Sleep works, compares time‑slice and pre‑emptive scheduling, clarifies why Sleep(1000) doesn't guarantee exact wake‑up timing, and shows how Sleep(0) yields the CPU to improve responsiveness in multithreaded applications.
CPU schedulingConcurrencyMultithreading
0 likes · 10 min read

The article explains how Thread.Sleep works by describing operating‑system scheduling concepts such as time‑slice and preemptive algorithms, answers common questions about Sleep(1000) and Sleep(0), and clarifies why the thread may not resume exactly after the specified delay.
.NET threadingOS schedulingpreemptive scheduling
0 likes · 10 min read

This article explains the purpose and behavior of the Thread.Sleep function in .NET, clarifies common misconceptions about its timing and effects, and relates it to operating‑system scheduling concepts such as time‑slice and preemptive multitasking.
C++CPU schedulingoperating system
0 likes · 9 min read

This article explains the true behavior of Thread.Sleep, how it interacts with operating system scheduling—both time‑slice and pre‑emptive models—and clarifies the differences between Sleep(milliseconds) and Sleep(0) for thread coordination.
ConcurrencySchedulingoperating system
0 likes · 9 min read

This article explains why waiting is essential in Selenium automation, compares Thread.sleep with implicit, explicit, and fluent waits, provides detailed Java code examples for each approach, and highlights best‑practice recommendations for reliable web element interaction.
Explicit WaitImplicit WaitJava
0 likes · 14 min read

This article explains the true behavior of Thread.Sleep, clarifies common misconceptions about its timing, compares Thread.Sleep(0) with no sleep, and uses a cake‑sharing analogy to illustrate time‑slice versus preemptive scheduling in operating systems.
C++CPU schedulingConcurrency
0 likes · 10 min read

This article explains the purpose of Thread.Sleep, clarifies common misconceptions about its timing behavior, compares Unix time‑slice and Windows preemptive scheduling using a cake‑eating analogy, and shows why Thread.Sleep(0) can trigger an immediate CPU‑competition reschedule to improve responsiveness.
CPU schedulingPreemptive Multitaskingoperating system
0 likes · 10 min read

Thread.Sleep pauses a thread for a specified time, influencing CPU competition; understanding its behavior—including the surprising effects of Sleep(0) and how operating systems schedule threads via time‑slicing or preemptive strategies—reveals why Sleep can affect responsiveness and why it’s used in tight loops.
CPU schedulingoperating systemthread::sleep
0 likes · 10 min read
