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

Hi Professor, I am not very familiar with c++, but I want to implement asynchronous operations, but MC_AWAIT reports an error. #30

Closed
yellow123Nike opened this issue Mar 23, 2023 · 4 comments

Comments

@yellow123Nike
Copy link

Hi Professor, I am not very familiar with c++, but I want to implement asynchronous operations, but MC_AWAIT reports an error.
std::thread th1( [& theirHashes](){MC_AWAIT(chl.recv(theirHashes));});

@yellow123Nike
Copy link
Author

image

@ladnir
Copy link
Contributor

ladnir commented Mar 23, 2023

That could work if you did

std::thread th1( [& theirHashes](){ macoro::sync_wait(chl.recv(theirHashes));});

But it's quite inefficient to spawn a thread to send one thing.

I'm generally, MC_AWAIT can only go inside a MC_BEGIN, MC_END coroutine block. See https://github.com/Visa-Research/coproto/blob/main/frontend/cpp14Tutorial.cpp

If you have c++ 20 you could also enable that and use the language support for coroutines.

@ladnir
Copy link
Contributor

ladnir commented Mar 23, 2023

If it's a one off thing then you can do the thread thing. Again, I made a long tutorial to inform people how to do this more efficiently. Take a look at it.

@yellow123Nike
Copy link
Author

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

3 participants