async icon indicating copy to clipboard operation
async copied to clipboard

Solution for using in DLL

Open ik9999 opened this issue 1 year ago • 0 comments

I had a problem: slog_async had been freezing execution of my windows dll because it had been getting stuck waiting for thread to finish with join() (even though the thread exists successfully). This had been happening while i was waiting for AsyncGuard to drop.

My solution was to add

                    while !join.is_finished() {
                        std::thread::sleep(std::time::Duration::from_millis(50));
                    }

above this line

https://github.com/slog-rs/async/blob/c2040ac96ddd189bb382e45bec9cb28338e5348c/lib.rs#L393

. Not a beautiful solution, so i decided not to make a pull request, but its good enough for me. Maybe it will help someone.

Im using build_with_guard(). And then before dll unloading i manually drop async_guard. With this fix drop(async_guard) finishes successfully and doesnt get stuck.

Update: Its still unsable (sometimes it still freezes). I had to remove

                    join.join().map_err(|err| {
                        println!("prev err: {:#?}", err);
                        io::Error::new(
                            io::ErrorKind::BrokenPipe,
                            "Logging thread worker join error",
                        )
                    })?;

at https://github.com/slog-rs/async/blob/c2040ac96ddd189bb382e45bec9cb28338e5348c/lib.rs#L393 completely to make it working (replaced with above-mentioned while basically).

ik9999 avatar Mar 01 '24 08:03 ik9999