IT lexicon › Programming › Exchanger

Exchanger

Programming På svenska → Updated: 2026-11-16

Synchronization point where exactly two threads exchange data and continue with each other's values.

An exchanger is a handoff primitive for two threads. One thread calls exchange(myData) and blocks; the second thread calls it with theirData; both unblock and each gets the other's value. No explicit locks needed—synchronization is implicit in the rendezvous. Useful for two-way pipelines (one thread producing, one consuming), temperature calibration loops where both sides must sync and swap buffers, or any protocol where exactly two parties coordinate.

Java provides Exchanger in java.util.concurrent. It's narrow in scope but elegant within it—few languages expose it, but the pattern appears repeatedly in practice.

← Back to the lexicon