nlib
LockFree.h File Reference

Lock-free algorithms are supported. More...

#include <new>
#include "nn/nlib/Config.h"
#include "nn/nlib/TypeTraits.h"
#include "nn/nlib/UniquePtr.h"
#include "nn/nlib/DynamicAlignedStorage.h"

Go to the source code of this file.

Classes

class  nn::nlib::LockFreePipe< N >
 When a single sender thread sends data and a single receiver thread receives that data, you can use this class to transfer data in a lock-free manner. More...
 
class  nn::nlib::ConstructorForLockFree< T >
 Class template for initializing an object. This should be specialized before use. More...
 
class  nn::nlib::DestructorForLockFree< T >
 Class template for destructing an object. This should be specialized before use. More...
 
class  nn::nlib::LockFreeStack< T >
 This class implements a lock-free stack. More...
 
class  nn::nlib::LockFreeQueue< T >
 This class implements a lock-free queue. More...
 
class  nn::nlib::LockFreePriorityQueue< T >
 Wraps nlib_mq with a class implementing a lock-free queue with a priority set. More...
 
class  nn::nlib::LockFreeBroadcastQueue< T >
 The specified number of listeners can obtain elements from the queue. After all the listeners have obtained elements, those elements are deleted from the queue. More...
 
class  nn::nlib::LockFreeUnitHeap
 A pool allocator that can allocate or free a fixed size of memory region in a lock free manner. More...
 

Namespaces

 nn::nlib
 Implements common features and features that are highly platform-dependent. Also refer to nlib Platform APIs. nlib_ns is an alias.
 

Functions

template<class T >
errno_t nn::nlib::LockFreeInit (T **ptr) noexcept
 Constructs an object in a thread safe manner. More...
 

Detailed Description

Lock-free algorithms are supported.

Description
As the number of CPU cores increases, synchronization using mutex has become an obstacle to performance improvement. A lock-free algorithm allows multiple threads to safely read and write data in parallel without locking shared data. This algorithm is enabled mainly by using a special CPU instruction, the CAS (Compare-and-Swap) instruction. Using a lock-free algorithm allows you to use shared data without blocking threads. You can also avoid issues that are often associated with locks, including deadlocks, livelocks and inverted priorities.

Definition in file LockFree.h.