Giter Site home page Giter Site logo

exit-left's Introduction

exit-left

verb;

1. To exit or disappear in a quiet, non-dramatic fashion, making way for more interesting events.

2. (imperative) Leave the scene, and don't make a fuss.

A rust synchronization primitive that can allow multiplexing of an underlying resource.

The idea is as such; You have many threads, all of them want to "wait" for some event to come through the pipeline, but the pipeline can give all kinds events in any order.

Worse still, only one thread can poll/block on this resource, and could have to deal with the unwanted events before it gets the one it would want.

This crate's Stage struct is the solution, any thread "heading" it would be responsible for routing the events, but it would be provided the tools to easily alert other threads waiting for "it's own" resource.

It does this via a Hash + Eq token type, which is passed to a ticket function, registering the token to be activated. Following this, the thread can then investigate the buffer, if it finds nothing, it can enter the stage, after which it will resume under one of the following three conditions;

  1. The thread is promoted to "heading" the stage, this can happen after the previous heading stage exits the stage, or if this thread is the first one to "enter" it.
  2. The thread passes a timeout parameter, and it passes by, the thread will then resume.
  3. A "heading" thread will notify this thread via its token, the thread will then resume.

Usage

A potential usage would be to poll a UdpSocket, which can receive packets from multiple sources, but also send to multiple.

Unlike a TcpStream, a UdpSocket has two potential modes, "Connected", or "Not Connected".

The former merely meaning that a filter is in place for a particular source, and all other packets are dropped.

Thus, normally, a UdpSocket in only "Connected" states would have to be constructed again and again for every local-remote tuple it would be used for, with local ports becoming unaccessible to the rest of the system after its been bind-ed.

So, the Stage can help many threads to await a socket at the same time, while only one does the actual routing work, while still leaving the ability to notify threads waiting for "their" endpoint.

exit-left's People

Contributors

shadowjonathan avatar

Watchers

James Cloos avatar  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.