tasks

Executing a Future in a Separate Thread with Coroutines

This post concludes my posts about co_return in C++20. I started with an eager future, continued with a lazy future. Today, I execute the future in a separate thread using coroutines as an implementation detail.

Read more
Views: 8968

Lazy Futures with Coroutines

Based on the coroutines-based implementation of a simple future in my last post "Implementing Simple Futures with Coroutines", I want to go today one big step further. I analyze the workflow of the simple future and make it lazy.

Read more
Views: 7951

Implementing Simple Futures with Coroutines

Instead of return, a coroutine uses co_return returning its result. In this post, I want to implement a simple coroutine using co_return.

Read more
Views: 14549

Synchronization with Atomics in C++20

Sender/receiver workflows are quite common for threads. In such a workflow, the receiver is waiting for the sender's notification before it continues to work. There are various ways to implement these workflows. With C++11, you can use condition variables or promise/future pairs; with C++20, you can use atomics.

Read more
Views: 12920

C++ Core Guidelines: More Rules to Concurrency and Parallelism

Writing multithreading programs is hard, even harder if the program should be correct. The rules of the C++ Core Guidelines guide you to write correct programs. The rules of this post will deal with data races, sharing of data, tasks, and the infamous keyword volatile.

Read more
Views: 23301

std::future Extensions

Tasks in the form of promises and futures have in C++11 an ambivalent reputation. On the one hand, they are a lot easier to use than threads or condition variables; on the other hand, they have a great deficiency. They can not be composed. C++20 will overcome this deficiency.

Read more
Tags: C++20, tasks
Views: 44826

Multithreaded: Summation with Minimal Synchronization

Until now I've used two strategies for the summation of a std::vector. First I did the whole math in one thread (Single Threaded: Summation of a vector); second multiple threads shared the same variable for the result (Multithreaded: Summation of a vector). In particular, the second strategy was extremely naive. In this post, I will apply my knowledge of both posts. My goal is it that the thread will perform their summation as independent from each other as possible and therefore reduce the synchronization overhead. 

Read more
Views: 17894

Thread Synchronization with Condition Variables or Tasks

In case you are using  promise and future to synchronize threads, they have a lot in common with condition variables. But most of the time, task are the better choice.

Read more
Views: 51985

The Special Futures

The parent of a thread has to take care of their child. The parent can wait until its child is done or detach itself from its child. But that is not really new. But that will not hold for std::async. The big charm of std::async is, that the parent has not taken care of its child.

Read more
Tags: async, tasks
Views: 23881

Promise and Future

With std::promise and std::future, you have full control over the task.

Read more
Tags: tasks
Views: 148875

My Newest E-Books

Course: Modern C++ Concurrency in Practice

Course: C++ Standard Library including C++14 & C++17

Course: Embedded Programming with Modern C++

Course: Generic Programming (Templates)

Course: C++ Fundamentals for Professionals

Interactive Course: The All-in-One Guide to C++20

Subscribe to the newsletter (+ pdf bundle)

Blog archive

Source Code

Visitors

Today 345

Yesterday 7029

Week 40669

Month 107335

All 7375175

Currently are 151 guests and no members online

Kubik-Rubik Joomla! Extensions

Latest comments