Code Monkey home page Code Monkey logo

rust-dispatch's People

Contributors

flier avatar jgh- avatar kvark avatar mehcode avatar ssheldon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-dispatch's Issues

Add support for QOS

It appears that you currently can't set the priority for the queue, and that it will just use the default priority instead. It would be great to allow for customization of this.

Dispatching on main queue doesn't seem to actually run on main thread.

I've created a more or less minimal example (based on the dispatch example) which shows that using exec_async on the main queue causes the closure to be executed on a different thread than the main thread:

extern crate dispatch;

use std::thread;
use std::process::exit;
use dispatch::{Queue, QueuePriority};
use objc::{{sel, sel_impl, msg_send, class}, runtime::{BOOL, YES, NO}};

pub fn is_main_thread() -> bool {
    unsafe {
        let thread = class!(NSThread);
        let b : BOOL = msg_send![thread, isMainThread];
        match b {
            YES => true,
            NO => false
        }
    }
}

fn test_on_main(queue: Queue) {

    queue.clone().exec_async(move || {
        let main = Queue::main();
        main.exec_async(|| {
            println!("Running from {:?} isMainThread? {}", thread::current().name(), is_main_thread());
            exit(0);
        });
    });
}

fn main() {
    // Read from stdin on a background queue so that the main queue is free
    // to handle other events. All printing still occurs through the main
    // queue to avoid jumbled output.
    cacao::utils::activate_cocoa_multithreading();
    println!("Initial Thread {:?} isMainThread? {}", thread::current().name(), is_main_thread());
    test_on_main(Queue::global(QueuePriority::Default));

    unsafe {
        dispatch::ffi::dispatch_main();
    }
}

Expected output:
Initial Thread ThreadId(1) isMainThread? true
This is another queue can execute on any thread ThreadId(X) isMainThread? false
Running from ThreadId(1) isMainThread? true

Actual output:
Initial Thread ThreadId(1) isMainThread? true
This is another queue can execute on any thread ThreadId(2) isMainThread? false
Running from ThreadId(3) isMainThread? false

DISPATCH_QUEUE_CONCURRENT flagged as undefined behavior

error[E0080]: this static likely exhibits undefined behavior
   --> /Users/mehcode/.cargo/registry/src/github.com-1ecc6299db9ec823/dispatch-0.1.3/src/ffi.rs:138:1
    |
138 | pub static DISPATCH_QUEUE_CONCURRENT: &'static dispatch_object_s = unsafe { &_dispatch_queue_attr_concurrent };
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a value of an uninhabited type at .<deref>
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior

❯ rustc --version
rustc 1.31.0-nightly (424a749a0 2018-10-21)

Make Once struct publicly available

There's a neat little Once struct that wraps dispatch_once, but it's not usable since there's no way to initialize a const UnsafeCell.

Once const fns are stabilized in rust-lang/rust#24111, the Once::new method can be marked const and the struct will be usable.

Implement optimized dispatch_once

dispatch_once_f is redefined as:

void _dispatch_once_f(dispatch_once_t *predicate, void *context, dispatch_function_t function)
{
    if (__builtin_expect(*predicate, ~0l) != ~0l) {
        dispatch_once_f(predicate, context, function);
    }
}

This requires the expect builtin, which isn't exposed as an intrinsic in Rust. Implementing this would be possible if rust-lang/rfcs#918 is accepted and implemented.

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.