These are chat archives for rust-lang/rust

3rd
Dec 2018
Josh
@joshgev
Dec 03 2018 03:02

Hi everyone! I am trying to debug a very strange issue that I've come across with some software I am working on. Basically I have some functions I've written that seem to work perfectly when I run them in a single-threaded application. When I run unit tests that test those functions, however, the tests succeed most of the time and fail every now and then. For fun, I tried running the unit tests but limiting the number of threads used to 1 (so that tests are guaranteed to run in series) and in this case the tests also seem to always work.

Now, these functions do some fancy stuff (eventually invoking CUDA calls, actually) so I suspect there is some concurrency stuff going on withinthe GPU. Trying to investigate in depth has proved difficult, especially since I can't reproduce the error consistently. When I try to run a program that uses the functions simultaneously in several threads, I just can't get the error to come up.

I wonder if something special is going on when rust runs unit tests in parallel that I might be overlooking when I try to reproduce the errors in a standalone application. Any thoughts here?

trsh
@trsh
Dec 03 2018 07:31
@joshgev are there some actual errors, or just the expected outcome fails?
Ali Shirvani
@alishir
Dec 03 2018 11:39
Hi there, I have a function that retures stream::iter_ok::<Response<String>>, io::Error>, what should be the function signature? I tried dyn futures::stream::Stream<Item = Response<String>, Error = io::Error> + 'static but I got error
fn handle_register(req: Request<()>) -> dyn futures::stream::Stream<Item = Response<String>, Error = io::Error> + 'static {
    let mut res = Response::builder();
    res.header("xhead", req.headers().get("xhead").unwrap().clone());
    let res = res.body("".to_string()).unwrap();
    stream::iter_ok::<_, io::Error>(vec![res])
}
Tim Robinson
@1tgr
Dec 03 2018 12:01
impl futures::stream::Stream<Item = ...etc...> should do it
dyn only works like &dyn Stream or Box<dyn Stream>... you could Box<dyn Stream<Item = ...etc...>> if you wanted
Ali Shirvani
@alishir
Dec 03 2018 12:10
@1tgr thanks a lot :thumbsup:
Rotem Yaari
@vmalloc
Dec 03 2018 15:41
Hi, I have a HashMap<String, Something>, and I have a potential key as a &str (not owned by me). How can I write a code that updates a value if a key exists already, or creates a new one if needed? I'm guessing entry doesn't help me here since it expects a String, and I don't want it to be constructed for every single lookup... any ideas?
Josh
@joshgev
Dec 03 2018 15:56
@trsh Ah, sorry; wasn't clear there. No errors, just expected outcome fails.
you avoid unnecessary allocations, but you will have to do the lookup into the HashMap twice on misses (entry avoids that)
Rotem Yaari
@vmalloc
Dec 03 2018 17:12
@maciejhirsz thanks! It's too bad there isn't a better idiom that is more like entry for that...
If inserts are infrequent enough I guess the performance hit isn't that bad though, so that'll do for me I guess
Denis Lisov
@tanriol
Dec 03 2018 17:17
@vmalloc There's an unstable RawEntry API from #54043 (tracked in #56167)
Rotem Yaari
@vmalloc
Dec 03 2018 17:24
@tanriol thanks! will take a look. Any idea when it's going to land in stable?
David Holroyd
@dholroyd
Dec 03 2018 22:50
Hi! I am able to cross-compile bin targets for rpi, but I can't seem to cross compile a benchmark -- is this a thing?
Specifically, the linker specified in .cargo/config seems to be ignored for cargo bench --no-run --target=...
Internal error occurred: Failed to find tool. Is `arm-linux-gnueabihf-gcc` installed?
but I specified,
[target.armv7-unknown-linux-gnueabihf]
linker = "tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc"
(and this seems to be used by cargo build --target=... ...)