Skip to content

Implement MessageQueue without locks #6837

Description

@brson

MessageQueue is the way schedulers communicate with each other. It is a multiple-producer, single-consumer unbounded queue.

Activity

  1. brson commented on Jun 5, 2013

    @brson
    ContributorAuthor

    @Thiez is working on this

  2. msullivan commented on Jul 26, 2013

    @msullivan
    Contributor

    How's this going?

  3. Thiez commented on Jul 28, 2013

    @Thiez
    Contributor

    I've had https://github.com/Thiez/rust/blob/ll-message-queue/src/libstd/rt/message_queue.rs lying around for a while now. It is a Michael-Scott lockless queue as described here http://www.cs.rochester.edu/~scott/papers/1996_PODC_queues.pdf . However, since Rust does not (at this time) have an intrinsic for double-word compare-and-swap, my version is considerably more vulnerable to the ABA-problem and thus I am hesitant to declare this queue complete.
    Adding a DWCAS intrinsic is not a good option as it is not supported on all the architectures we target. I think the best option would be to have a ABA-safe atomic pointer type defined in the library (it would help with the implementation of other datastructures as well). I suspect such a thing could be implemented for each target architecture with some #[cfg(target_arch = <sometarget>)] annotations; using LLVM would be tricky as it has no IR instruction that captures the semantics of of LL/SC (on architectures such as ARM).
    I have no MIPS or multicore ARM devices lying around so I would not be able to test such a pointer.

    To summarize, the basic algorithm is implemented and appears to work (without leaking memory, or so valgrind tells me) but it's going to fail randomly (but rarely) when at least two threads are writing and one thread is reading.
    Currently there's manual malloc/free in the code but now that ~ has lost the headers the malloc could be replaced by a normal ~ followed by a transmute (and transmute back to ~ to delete).

    Suggestions are welcome.

  4. plokhotnyuk commented on Aug 7, 2013

    @plokhotnyuk
  5. brson commented on Aug 17, 2013

    @brson
    ContributorAuthor

    The biggest place where we need to reduce lock contention is the global sleeper list #6838. Its lock is just getting hammered constantly. There are lots of ways we might fix this but an obvious one to replace it with a lock-free queue.

  6. Thiez commented on Sep 2, 2013

    @Thiez
    Contributor

    @plokhotnyuk thanks for that link, implementing it in rust was incredibly easy https://github.com/Thiez/rust/blob/better-message-queue/src/libstd/rt/message_queue.rs
    @brson did you have a good benchmark for message-passing lying around?

  7. alexcrichton commented on Oct 29, 2013

    @alexcrichton
    Member

    Closed by #9710

  8. added a commit that references this issue on Mar 25, 2021
  9. added a commit that references this issue on Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-runtimeArea: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions