Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code not working properly without std::thread::spawn inside scope.spawn() #180

Closed
gnzlbg opened this issue Jul 5, 2018 · 2 comments
Closed

Comments

@gnzlbg
Copy link

gnzlbg commented Jul 5, 2018

The following gist contains two examples, the first one produces no output, the second does.

From the docs I couldn't find any reasons why doing a std::thread::spawn inside a crossbeam::scope(|s| s.spawn(|| std::thread::spawn(|| ...)) should be necessary.

https://gist.github.com/gnzlbg/09d7e546df2215bee83fc5fe02840292

@Vtec234
Copy link
Member

Vtec234 commented Jul 5, 2018

Because your threading logic is wrong - from the indicatif documentation for join():

Waits for all progress bars to report that they are finished.

You need to call this as this will request the draw instructions from the remote progress bars. Not calling this will deadlock your program.

So you need to call join() or join_and_clear() for indicatif to display your progress bar, but you call it after the crossbeam::scope exits, which means that all the work has already been done, because crossbeam::scope joins all threads which were created in it before it can exit.

On the other hand, in works.rs you spawn a detached thread, which can keep going after the crossbeam::scope is over, so that the join call displays the detached thread's progress.

@Vtec234 Vtec234 closed this as completed Jul 5, 2018
@gnzlbg
Copy link
Author

gnzlbg commented Jul 6, 2018

@Vtec234 you are correct, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants