Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets #9

Merged
merged 2 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
File renamed without changes
File renamed without changes
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Atom
====

[![Build Status](https://travis-ci.org/slide-rs/atom.svg?branch=master)](https://travis-ci.org/csherratt/atom)
[![Build Status](https://travis-ci.org/slide-rs/atom.svg?branch=master)](https://travis-ci.org/slide-rs/atom)
[![Atom](http://meritbadge.herokuapp.com/atom)](https://crates.io/crates/atom)

`Atom` is a simple abstraction around Rust's `AtomicPtr`. It provides a simple, wait-free way to exchange
data between threads safely. `Atom` is built around the principle that an atomic swap can be used to
safely emulate Rust's ownership.

![store](https://raw.githubusercontent.com/csherratt/atom/master/.store.png)
![store](https://raw.githubusercontent.com/slide-rs/atom/master/assets/store.png)

Using [`store`](https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html#method.store) to set a shared
atomic pointer is unsafe in rust (or any language) because the contents of the pointer can be overwritten at any
point in time causing the contents of the pointer to be lost. This can cause your system to leak memory, and
if you are expecting that memory to do something useful (like wake a sleeping thread), you are in trouble.

![load](https://raw.githubusercontent.com/csherratt/atom/master/.load.png)
![load](https://raw.githubusercontent.com/slide-rs/atom/master/assets/load.png)

Similarly, [`load`](https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html#method.store)
is unsafe since there is no guarantee that that pointer will live for even a cycle after you have read it. Another
thread may modify the pointer, or free it. For `load` to be safe you need to have some outside contract to preserve
the correct ownership semantics.

![swap](https://raw.githubusercontent.com/csherratt/atom/master/.swap.png)
![swap](https://raw.githubusercontent.com/slide-rs/atom/master/assets/swap.png)

A [`swap`](https://doc.rust-lang.org/std/sync/atomic/struct.AtomicPtr.html#method.swap) is special as it allows
a reference to be exchanged without the risk of that pointer being freed, or stomped on. When a thread
Expand Down