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

关于submitForReturn函数是否能执行带参数的函数的问题 #19

Open
Capsfly opened this issue Apr 6, 2023 · 3 comments
Open

Comments

@Capsfly
Copy link

Capsfly commented Apr 6, 2023

截屏2023-04-07 00 47 09

如题,可以看出这个函数是不是只实现了 执行不带参数的函数功能啊?因为在调用std::result_of和std::packaged_task的时候,模板里面都没加参数的类型。如果我理解错误的话,up方不方便给一个普通函数的例子啊?
@CodingHanYa
Copy link
Owner

是不带参数的,你可以用std::bind或者lambda捕获局部变量来传入参数。

@Capsfly
Copy link
Author

Capsfly commented Apr 7, 2023

截屏2023-04-07 10 29 00

我试了一下,好像不行呀,up能给个例子嘛? 这是compute函数的定义

截屏2023-04-07 10 29 20

@CodingHanYa
Copy link
Owner

CodingHanYa commented Apr 7, 2023

#include <hipe/hipe.h>

double func(double x) {
    hipe::util::print("hello world");
    return x;
}

int main() {
    hipe::SteadyThreadPond poo(10);
    auto tmp = poo.submitForReturn(std::bind(func, 2.5));
    poo.waitForTasks();
    hipe::util::print(tmp.get());
}

没问题呀

jack@LAPTOP-9HN8DLAB:~/code/Hipe/interfaces$ g++ tmp.cc -I ../include -lpthread && ./a.out
hello world
2.5

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