• Talk on Asynchronous IO with Boost.Asio at CppCon 2016 by Michael Caisse.
  • Best documentation for Boost:asio? : StackOverflow
  • Boost::Asio Notes - Part 1: Link
    • I/O services and I/O objects
    • Scalability and Multithreading
    • An example network programming using Asio
    • What is a handler and what is a work?
    • post(), poll() and poll_one().
    • Need for boost::asio::io_service::work.
    • Making an event loop class in C++ using Boost::asio.
    • Preventing run() from returning using boost::asio::executor_work_guard.
    • io_service::stop(), using boost::bind() to create handler objects.
    • Difference between post() and dispatch() in boost::asio.
    • A simple Fibonacii calculation using boost::asio.
    • Serializing work-load with io_service::strand.
  • Boost::Asio Notes - Part 2: Link
    • Error handling in boost::asio.
    • boost::asio::timers
    • Recurring timer - example.
    • Sample code combinting deadline_timer and io_service::strand.
    • Network basics: connectors and acceptors for TCP.
    • Creating a simple tcp servier.
    • Notes related to cpp-con-2016 talk by Michael Caisse.

  • Move Constructors and Move Assignemnt operators in C++: Microsoft Docs
  • When to use std::async vs. std::thread?: StackOverflow
  • std::async in c++11
  • What is std::move() and when should it be used? : StackOverflow
  • Bjarne Stroustroup's take on std::async:
    "...don't even think of using async() to launch tasks that do I/O, manipulate mutexes, or in other ways interact with other tasks. The idea behind async() is the same as the idea behind the range-forstatement: Provide a simple way to handle the simplest, rather common, case and leave the more complex examples to the fully general mechanism."
  • std::push_back() vs. std::emplace_back() on std::vector: StackOverflow
  • When to use virtual destructors: StackOverflow
  • Unnamed namespaces in C++: StackOverflow

  • Condition variable - to synchronize the execution order of threads.
  • producer-consumer example with with busy-wait and with std::condition_variable.
  • wait() : makes the current thread to block until the condition variable get signaled or a spurious wake up happens.
  • notify_one(): if any threads are waiting on same conditional variable object then notify_one unblocks one of the waiting threads.
  • wiki: Spurious Wakeup
  • Stackoverflow: why do I need condition variable?

  • Use of volatile keyword: StackOverflow
  • mutable keyword: StackOverflow
  • Differences in having const keyword in the function argument and in the function signature: StackOverflow
  • std::function vs. function pointers in C++: StackOverflow
  • Function pointers have the disadvantage of not being able to capture some context. You won't be able to, for example, pass a lambda function as a callback which captures some context variables.
  • What exactly is std::atomic: StackOverflow
  • C++11 - standardized memory model: StackOverflow
  • std::memory_order: cppreference
  • C++ and Beyond 2012: Atomic<> weapons (by Herb Sutter): MSDN link (part 1)
  • C++ and Beyond 2012: Atomic<> weapons (by Herb Sutter): MSDN link (part 2)

  • Builder design pattern (c++): Blogspot link
  • Template implementation and compiler: link
  • Splitting template classes into header and cpp files: link
  • Are header-only libraries efficient? : StackOverflow
  • Difference between .h and .hpp header files: StackOverflow
  • __FILE__, __LINE__, and __FUNCTION__ usage in C++: StackOverflow
  • What is the difference between std::array and std::vector? When do you use one over other?: StackOverflow
  • shared_ptr Notes: link
  • CRTP (Curiously Recurring Template Pattern): link

  • Race condition and mutex
  • std::mutex
  • mutex1.lock() and mutex1.unlock()
  • RAII using std::lock_guard<std::mutex>
  • Avoiding data race:
    • Use mutex to synchronize data access
    • Never leak a handle to the data outside.
    • Design interface appropriately
  • Avoiding Deadlock
    • prefer locking single mutex
    • avoid locking a mutex and then calling user defined function
    • use std::lock() to lock more than one mutex
    • Try locking the mutex in the same order in all threads.

  • std::future, std::promise and std::async
  • Future and promise provide a convenience way to communicate between threads.
  • std::future return value from the std::async call forms a channel to return a value from the child thread to the parent thread.
  • std::launch::deferred and std::launch::async

  • Unique lock and lazy intialization
  • std::unique_lock<mutex> gives you a more flexible way to implement a fine-grained locking mechanism; unlike lock_guard, it provides lock() and unlock() functionalities.
  • Difference between lock_guard and unique_lock
  • The wrapper classes of mutex, whether it be lock_guard or unique_lock, cannot be copied.
  • lock_guard cannot be moved but a unique_lock can be moved.
  • When you std::move a std::unique_lock, you are transferring the ownership of the lock from one unique-lock to another unique-lock.
  • stackoverflow: Why lock_guard is not movable?
  • std::once_flag and std::call_once

  • StackOverflow: Static, dynamic and reinterpret cast
  • C-style cast and function-style cast are casts using (type)object or type(object), respectively, and are functionally equivalent.
  • reinterpret_cast is the most dangerous cast, and should be used very sparingly. It turns one type directly into another — such as casting the value from one pointer to another, or storing a pointer in an int, or all sorts of other nasty things.
  • dynamic_cast is exclusively used for handling polymorphism. You can cast a pointer or reference to any polymorphic type to any other class type (a polymorphic type has at least one virtual function, declared or inherited).
  • The dynamic_cast will seek out the desired object and return it if possible. If it can't, it will return nullptr in the case of a pointer, or throw std::bad_cast in the case of a reference.
  • Use const_cast for casting away const/volatile. Avoid this unless you are stuck using a const-incorrect API.
  • One example where this comes handy is iterating through some container (like stl::set) which only returns its elements as const to make sure you don't change its key. However if your intent is to modify object's non-key members then it should be ok. You can use const_cast to remove constness.

  • C++11 threading
  • std::thread
  • thread1.join()
  • thread1.detatch()
  • thread1.joinable()
  • when you detatch the thread, it becomes daemon.
  • A parameter to a thread is always passed by value.
  • A thread object can only be moved and cannot be copied.
  • std::this_thread::get_id()
  • Oversubscription: the number of threads trying to run exceeds the number of available logical-cores/processors on the machine.
  • std::thread::hardware_concurrency()

C++ Part 2