0

Rust – Thread Synchronization using Barrier

Last Updated on

This post is about a thread synchronization using Barrier using std::sync::Barrier.

Basic Idea

The basic idea of using barriers is to pause threads at a certain point until all other expected threads are started and paused at the same point. Only then the “barrier” breaks and allows all the threads to proceed execution.

Codes

The codes make all threads wait until all 5 threads called the wait()  function.

Output

Note that lines 6-10 are not guaranteed to be the same every time the codes are run.

Avatar

Karl San Gabriel

Professional Software Developer