Coder Social home page Coder Social logo

volatile's Introduction

volatile

Build Status Docs.rs Badge

Provides volatile wrapper types for raw pointers.

The volatile wrapper types in this crate wrap a pointer to any Copy-able type and provide volatile memory access to wrapped value. Volatile memory accesses are never optimized away by the compiler, and are useful in many low-level systems programming and concurrent contexts.

This crate provides two different wrapper types: VolatilePtr and VolatileRef. The difference between the two types is that the former behaves like a raw pointer, while the latter behaves like a Rust reference type. For example, VolatilePtr can be freely copied, but not sent across threads because this could introduce mutable aliasing. The VolatileRef type, on the other hand, requires exclusive access for mutation, so that sharing it across thread boundaries is safe.

Both wrapper types do not enforce any atomicity guarantees; to also get atomicity, consider looking at the Atomic wrapper types found in libcore or libstd.

Why is there no VolatileCell?

Many people expressed interest in a VolatileCell type, i.e. a transparent wrapper type that owns the wrapped value. Such a type would be similar to core::cell::Cell, with the difference that all methods are volatile. Unfortunately, it is not sound to implement such a VolatileCell type in Rust. The reason is that Rust and LLVM consider & and &mut references as dereferencable. This means that the compiler is allowed to freely access the referenced value without any restrictions. So no matter how a VolatileCell type is implemented, the compiler is allowed to perform non-volatile read operations of the contained value, which can lead to unexpected (or even undefined?) behavior. For more details, see the discussion in our repository and in the unsafe-code-guidelines repository.

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

volatile's People

Contributors

alichraghi avatar freax13 avatar hawkw avatar joycebrum avatar kernelfreeze avatar phil-opp avatar toku-sa-n avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.