Git Product home page Git Product logo

atomic-wait's Introduction

Cross platform atomic wait and wake (aka futex) functionality.

This crate only supports functionality that's available on all of Linux, FreeBSD, Windows, and macOS. That is:

  • Only AtomicU32 is supported. (Linux currently only supports 32-bit futexes.)
  • Only the "wait", "wake one", and "wake all" operations are supported. (Linux supports more operations, but Windows and macOS don't.)
  • No timeouts. (macOS doesn't have a stable/public API for timeouts.)
  • The wake operations don't return the number of threads woken up. (Only Linux supports this.)

Supported platforms: Linux 2.6.22+, FreeBSD 11+, Windows 8+, Windows Server 2012+, macOS 11+, iOS 14+, watchOS 7+.

Usage

use std::sync::atomic::AtomicU32;
use atomic_wait::{wait, wake_one, wake_all};

let a = AtomicU32::new(0);

wait(&a, 1); // If the value is 1, wait.

wake_one(&a); // Wake one waiting thread.

wake_all(&a); // Wake all waiting threads.

Implementation

On Linux, this uses the SYS_futex syscall.

On FreeBSD, this uses the _umtx_op syscall.

On Windows, this uses the WaitOnAddress and WakeByAddress APIs.

On macOS (and iOS and watchOS), this uses libc++, making use of the same (ABI-stable) functions behind C++20's atomic_wait and atomic_notify functions.

atomic-wait's People

Contributors

m-ou-se avatar kostikbel 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.