Let’s assume you want to implement a function to update the maximum value or a variable. Issue: To prevent a
Continue readingCategory: Concurrency
Singleton file logger with concurrent queue (C++)
Advantages … of a singleton is that you don’t have to pass it into every class you want to log
Continue readingAssembler instructions for atomics (C++)
std::atomic Intel / AMD ARM (with LSE) fetch_add() LOCK XADD1,2,3,4,5 LDADD1, LDADDA2, LDADDL3, LDADDAL4,5 fetch_sub() fetch_and() LOCK AND1,2,3,4,5 LDCLR1, LDCLRA2,
Continue readingstd::jthread (C++)
With C++20 you can use std::jthread (“Cooperatively Interruptible Joining Thread”), which does the stop request and the joining in its
Continue readingThreaded pi calculation with concurrent queue (C++)
Code $ g++ main.cpp -ltbb -lpthread Future Switch to a thread pool to execute the different calculations in parallel.
Continue readingMemory order for atomics (C++)
Overview Memory order Description memory_order_relaxed Unsafest, No ordering is guaranteed. memory_order_acquire A load operation, No reads or writes in the
Continue readingParallelize without own threading (oneTBB)
oneTBB The library abstracts all the thread handling from you, like the task scheduler and its thread pool. Features (selection)
Continue readingTypes of mutexes and locks (C++)
Mutexes (Selection) … synchronizes the access on critical sections std::mutex Provides exclusive access (can only be pulled by one thread
Continue readingActive vs. passive waiting (C++)
Active waiting Don’t use this approach, because it will unnecessarily consume CPU time. The sleep reduces the CPU consumption, but
Continue readingstd::recursive_mutex (C++)
The std::mutex is a non-recursive mutex and therefore can’t be locked again from the same thread before getting unlocked. This
Continue reading