atomic-story 0.1.1

An brief overview of atomics and memory ordering on a multi-threaded context with examples.
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 2 items with examples
  • Size
  • Source code size: 10.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 280.34 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 22s Average build duration of successful builds.
  • all releases: 22s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • blasrodri/atomic-story
    13 3 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • blasrodri

Atomic Story

Understanding atomics and memory ordering takes time, and it might also be a painful journey. This is mine.

I felt that having a repo with simple unit tests would help me enhance my understanding on the topic. Besides, it's a very compact way of knowledge transfer - that's why I am making this public.

Anatomy

Counter one writer one reader

This is the simples example. Using Relaxed is more than enough, since we're only checking the final value after all threads have incremented the value.

Two numbers with a dependency between them.

This example is more interesting. There are two threads: a writer and a reader. And two values, num_a and num_b. This exmample explores different Ordering combinations, and how they can yield different results.

How to run the tests/examples

They are just Rust tests. Run:

cargo test