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

线程返回超时问题 #33

Open
ChaoII opened this issue Nov 10, 2023 · 2 comments
Open

线程返回超时问题 #33

ChaoII opened this issue Nov 10, 2023 · 2 comments

Comments

@ChaoII
Copy link

ChaoII commented Nov 10, 2023

workbranch br(2);
auto result = br.submit([](){
    return xx;
});
if(result.wait_for(xx) == std::future::time_out){
    // 请问一下 如过超时,如何杀掉执行当前超时任务的线程。
}else{
    result.get();
}

请问一下 如过超时,如何杀掉执行当前超时任务的线程。

@CodingHanYa
Copy link
Owner

线程不能随便杀掉。尽量确保不要有阻塞任务,也可以折中地用动态增加线程来解决。

@CodingHanYa
Copy link
Owner

这里wait_for可以指定一段时间,可以确保主线程不会因为异步线程而阻塞。

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

No branches or pull requests

2 participants