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

Asynchronous/Threaded Transfers #11

Open
gggrafff opened this issue Dec 21, 2020 · 3 comments
Open

Asynchronous/Threaded Transfers #11

gggrafff opened this issue Dec 21, 2020 · 3 comments

Comments

@gggrafff
Copy link

Good afternoon.
The wording of the name of this example is a bit confusing

std::wcout << L"Test 3 - Asynchronous/Threaded Transfers" << std::endl << std::endl;

I think it is not necessary to mix the concepts of asynchronous and multi-threading.
Asynchronous is not about creating parallel threads, but switching between tasks within a thread. Asynchronous can be implemented using coroutines, which were added in C++20.
Example:
If we need to make simultaneous requests, then we can create separate threads for each request. All these threads will be waiting for a response, this is not very efficient if waiting for a response takes a significant part of the time. In this case, it is more efficient to create requests in one thread, and while waiting for a response to one request, process the response to another request. This will allow you to spend less time waiting. In addition, switching between threads is much more expensive than switching between coroutines.

Also, I find it not very efficient to create and delete threads for each new request if the requests need to be sent frequently.

What do you think about it?
Thanks

@gggrafff
Copy link
Author

gggrafff commented Jan 2, 2021

libusb has asynchronous transmission. We only need to make a wrapper for it.
http://libusb.sourceforge.net/api-1.0/group__libusb__asyncio.html

@gggrafff
Copy link
Author

gggrafff commented Dec 7, 2021

We can use std::async also instead of creating a new thread for each new transfer. It may be implemented as thread pool sometimes. Or we can implement own thread pool. It will help reduce the cost of creating threads and improve performance.

@mcuee
Copy link

mcuee commented Feb 11, 2023

This will be an important improvement for libusbpp.

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