テーマ: concurrency
-
Cancellation and deadlines in Go with context.Context
Thread a context.Context from the incoming request through every call that can block, derive child contexts with WithTimeout or WithCancel, always call the cancel function, and check ctx.Done() in loops so that a client disconnect or a deadline stops the whole tree of goroutines instead of leaving them running.
-
asyncio が役立つ場合と役立たない場合
asyncio は await の地点で処理を中断し、一つのスレッドで多数の I/O 待ちのタスクを動かす。CPU 処理が支配的なコードを速くするものではなく、コルーチン内のブロッキング呼び出しはループ全体を止める。
-
トランザクション分離レベルの実践
Read Committed、Repeatable Read、Serializable は並行性と一貫性の間で折り合いをつけます。各レベルが許す異常を理解すれば、明示的なロックや再試行が必要な場面を判断できます。
-
Pythonの処理にスレッド、プロセス、asyncioのどれを選ぶか
まず頻繁に通る処理経路を分類します。I/O待ちにはasyncio(多数の接続、非同期ライブラリ)かスレッドプール(少数のブロッキング呼び出し)が向きます。純粋なPythonのCPU処理にはプロセスかフリースレッドビルドが必要で、GILを解放するネイティブコードにはスレッドを使えます。各プールに上限を設け、プロセスの起動方式を明示し、終了処理を書きます。
-
返されたリビジョンを使って書き込み後の読み取りを検証する
安定した識別子とリビジョンで書き込みを確認し、並行して行われた新しい更新を、自分が送信した内容そのものと取り違えないようにする。
-
Handle stale write tokens as reread signals
Recover from a failed write precondition by rereading and rebuilding the intended change against the current version.
-
Preventing concurrent runs of an admin script: flock, lockf and a named mutex on Windows
A scheduled or agent-triggered admin script that can be started again before the previous run finished needs a lock, not a hope that it never happens. flock(1) on Linux and lockf(1) on FreeBSD tie a kernel-level advisory lock to a running process so it cannot go stale the way a leftover PID file can; Windows scripts get the equivalent with a named System.Threading.Mutex.
-
At what workload does the free-threaded CPython build beat a process pool for a mixed I/O and CPU service?
Open question: the free-threaded build removes the GIL but adds single-threaded overhead and may fall back to the GIL when an unprepared extension is imported, while process pools pay for pickling and memory duplication; for which CPU-to-wait ratios, working sets and core counts does a thread pool on the free-threaded build deliver more throughput per core?
-
C# async/await pitfalls: sync-over-async, async void and ConfigureAwait
The classic mistakes in C# asynchronous code are blocking on a Task with .Result, .Wait() or GetAwaiter().GetResult() (deadlocks under a single-threaded SynchronizationContext, thread-pool starvation on servers), async void methods whose exceptions cannot be caught, and misplacing ConfigureAwait(false), which belongs in general-purpose libraries and not in application code.
-
Java virtual threads in outline: what changes and what does not
JEP 444 (JDK 21) adds virtual threads: cheap threads scheduled by the JDK onto a small pool of carrier platform threads, which unmount while blocked on most JDK I/O so that thread-per-request code scales without an asynchronous style. They are not faster, must never be pooled, and until JEP 491 (JDK 24) blocking inside synchronized pinned the carrier.
-
Use expiring leases for distributed jobs
Protect a reclaimed job from a delayed previous worker with ownership checks and a monotonically increasing fencing token.
-
The GIL: what it serialises and what it does not make safe
The global interpreter lock lets only one thread execute Python bytecode at a time and protects the interpreter's own structures, not the program's invariants: read-modify-write sequences such as counter += 1 or check-then-set on a dict still need a threading.Lock. Free-threaded builds keep the same rule.
-
Goroutines, channels and the sync package: Go concurrency in outline
A go statement runs a function call concurrently on a cheap, growable stack; channels move values between goroutines and block until both sides are ready; sync.WaitGroup, Mutex and Once cover the cases where sharing memory is simpler. A data race is a bug whose outcome the memory model only partly constrains, and the -race detector is the tool for finding it.
-
Jev の判断後、副作用の前に状態を再検証する
関連するレコード、権限、または方針が変わった後に、以前のアプリケーション状態についての判断を無批判に適用しないようにする。
-
Go の競合検出の範囲:問題のない実行から未実行の経路については何も分からない
go test -race の結果を、起動と終了を含む実際に実行した並行処理経路に結び付けます。
-
Tokio の Send エラー:await をまたいで保持する状態を調べる
unsafe なトレイト実装を追加せず、中断をまたいで何が残るかを調べ、spawn する future を修正します。
-
Bound concurrency per host and account
Control simultaneous tool calls separately from request rate, with bounded queues and cancellation-safe permit release.
-
ThreadSanitizer のトリアージ:欠けている同期契約を明らかにする
競合する両方のアクセス経路を読み、それらを結ぶ所有権または同期の規則を修正する。
機械可読: JSON