Code Explainers
Code explainers tagged #mutex
go
package logsample import ( "sync"
A per-key rate limiter for log sampling
rate-limiting
concurrency
time-windows
Intermediate
7 steps
ruby
require "thread" class ConnectionPool class TimeoutError < StandardError; end
Building a thread-safe connection pool in Ruby
concurrency
resource-pooling
mutex
Advanced
8 steps
go
package metrics import ( "sync"
A thread-safe sliding-window average in Go
concurrency
sliding-window
running-average
Intermediate
8 steps
go
package breaker import ( "errors"
How a circuit breaker works in Go
circuit-breaker
state-machine
concurrency
Intermediate
8 steps
go
package editor import ( "context"
How a debouncer coalesces bursts in Go
debounce
concurrency
timers
Intermediate
8 steps
go
package cache import ( "sync"
A thread-safe TTL cache in Go
concurrency
mutex
caching
Intermediate
9 steps
ruby
class CircuitBreaker class OpenCircuitError < StandardError; end def initialize(failure_threshold: 5, reset_timeout: 30, half_open_max: 1)
How a circuit breaker guards failing calls
state-machine
fault-tolerance
concurrency
Advanced
9 steps
ruby
class Debouncer def initialize(delay:) @delay = delay @mutex = Mutex.new
A thread-safe debouncer in Ruby
concurrency
debouncing
mutex
Advanced
5 steps
go
package ratelimit import ( "context"
A token bucket rate limiter in Go
rate-limiting
concurrency
goroutines
Intermediate
7 steps
rust
use std::sync::{Arc, Mutex, MutexGuard}; use std::time::Instant; pub struct TimedGuard<'a, T> {
A self-timing mutex guard in Rust
raii
mutex
deref
Advanced
7 steps
go
package scheduler import ( "context"
A context-aware heartbeat ticker in Go
concurrency
channels
context
Intermediate
5 steps
rust
use std::collections::HashMap; use std::sync::{Arc, Mutex}; use std::thread;
Aggregating metrics across threads in Rust
concurrency
shared-state
mutex
Intermediate
7 steps
go
package debounce import ( "sync"
Building a debouncer in Go
concurrency
debounce
timers
Intermediate
6 steps
ruby
class Throttle def initialize(interval) @interval = interval @mutex = Mutex.new
A thread-safe throttle in Ruby
concurrency
rate-limiting
mutex
Intermediate
7 steps
ruby
class ThreadSafeCounter def initialize(initial = 0) @count = initial @mutex = Mutex.new
A thread-safe counter with Mutex in Ruby
concurrency
mutex
thread-safety
Intermediate
6 steps
go
package main import "sync"
Mutex vs RWMutex in Go
concurrency
mutex
synchronization
Intermediate
6 steps