Code Monkey home page Code Monkey logo

libasync's Introduction

libasync

What is it?

libasync is a C++11 library for concurrency and multithreading.

libasync allows you to do concurrent work on multithreaded pools and serial queues. There's barriers and work groups for synchronization. Inspired by the great dispatch library. It also provides APIs to create data-driven pipelines composed of different compute steps.

libasync only uses APIs defined in the C++11 standard. This means that it's fully portable as it doesn't depend on platform specific libraries - provided your C++ compiler correctly implements the standard.

How to use it?

Pools

// multithreaded pool
async::pool pool;

pool.async([]{
	work();
});

pool.async([]{
	work();
});

pool.barrier();

pool.async([]{
	work_post_barrier();
};

// wait for the tasks to be done
pool.wait();

pool.apply(n, [](size_t idx){
	work_chunk(idx);
});

// run and wait for completion
pool.sync([]{
	task();
};

Queues

// serial queue
async::queue queue;

queue.async([]{
	work();
};

// run and wait for completion
queue.sync([]{
	task();
};

// using a queue as a lock
async::queue lock_queue;
async::pool pool;

pool.async([&]{
	work();

	lock_queue.sync([]{
		critical();
	};
};

pool.async([&]{
	work();

	lock_queue.sync([]{
		critical();
	};
};

Groups

async::group group;
async::pool pool;

pool.async(group, []{
	work();
});

pool.async(group, []{
	work();
});

pool.async([]{
	unrelated_work();
});

group.enter();
work();
group.leave();

group.wait();

libasync's People

Contributors

florischabert avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.