Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/poisonousjohn/async
C++11 module for asynchronous operations allowing to separate jobs by specific threads
https://github.com/poisonousjohn/async
Last synced: 5 days ago
JSON representation
C++11 module for asynchronous operations allowing to separate jobs by specific threads
- Host: GitHub
- URL: https://github.com/poisonousjohn/async
- Owner: PoisonousJohn
- License: mit
- Created: 2014-08-28T17:37:07.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-05T09:26:42.000Z (over 7 years ago)
- Last Synced: 2023-03-22T20:42:31.199Z (over 1 year ago)
- Language: C++
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Async
## Purpose
Async is a module for asynchronous operations designed to use in games. My purpose was to create a custom thread pool that will allow to enqueue tasks to SEPARATE threads. E.g. you can enqueue resource loading tasks to thread 1, network tasks to thread 2 and etc.
This is extremely important in mobile apps due to limited processor resources. We can't create lot of threads and priority of the tasks is not enough, because there can be situtation when all workers are busy with resource loading tasks and you want to do a network query as soon as possible, but worker won't do highest priority task while it is doing other job and you have to wait.
Separating tasks by specific threads solves this problem. Network tasks that run in thread 1 won't block other tasks running in thread 2
## Simple example
```c++
#include
#include
#include "Async.h"using namespace poison;
int main(int argc, const char * argv[])
{
Async::Async async;
async.doSync([]() {
std::cout << "Synchronous task" << std::endl;
});
async.doAsync([](){
std::cout << "Asynchronous task" << std::endl;
}, [](){
std::cout << "Synchronous callback" << std::endl;
});
bool stop = false;
std::thread addLater([&](){
std::this_thread::sleep_for(std::chrono::milliseconds(2500));
async.doAsync([](){
std::cout << "later" << std::endl;
}, [&](){
std::cout << "later fg" << std::endl;
stop = true;
});
});
addLater.detach();
std::thread asyncThread([&]{
while (!stop) {
// your engine should invoke this method every frame
// this method finishes tasks and calls synchronous callbacks
async.update();
}
});
asyncThread.join();
return 0;
}
```## Requirements
- C++11
- Boost