This page has been translated automatically.
Видеоуроки
Интерфейс
Основы
Продвинутый уровень
Подсказки и советы
Основы
Программирование на C#
Рендеринг
Профессиональный уровень (SIM)
Принципы работы
Свойства (properties)
Компонентная Система
Рендер
Физика
Браузер SDK 2
Лицензирование и типы лицензий
Дополнения (Add-Ons)
Демонстрационные проекты
Samples
Редактор UnigineEditor
Обзор интерфейса
Работа с ассетами
Контроль версий
Настройки и предпочтения
Работа с проектами
Настройка параметров ноды
Setting Up Materials
Настройка свойств
Освещение
Sandworm
Использование инструментов редактора для конкретных задач
Расширение функционала редактора
Встроенные объекты
Ноды (Nodes)
Объекты (Objects)
Эффекты
Декали
Источники света
Geodetics
World-ноды
Звуковые объекты
Объекты поиска пути
Player-ноды
Программирование
Основы
Настройка среды разработки
Примеры использования
C++
C#
UnigineScript
Унифицированный язык шейдеров UUSL (Unified UNIGINE Shader Language)
Плагины
Форматы файлов
Материалы и шейдеры
Rebuilding the Engine Tools
Интерфейс пользователя (GUI)
Двойная точность координат
Справочник API
Animations-Related Classes
Containers
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Objects-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
IG Plugin
CIGIConnector Plugin
Rendering-Related Classes
VR-Related Classes
Работа с контентом
Оптимизация контента
Материалы
Визуальный редактор материалов
Material Nodes Library
Miscellaneous
Input
Math
Matrix
Textures
Art Samples
Учебные материалы

Multithreading Functionality

UNIGINE Multithreading Functionality provides cross-platform, low and high-level abstractions for building efficient multithreaded systems.

It includes thread management, mutual exclusion primitives (mutexes), scoped lock wrappers, and full set of atomic operations and classes.

Mutexes and Locks#

Mutexes (mutual exclusions) are the primary tool for preventing simultaneous access to shared resources. UNIGINE provides various mutex types optimized for spinlocks, native system APIs, and reentrant behavior.

In most cases, you will only need a limited set of high-level classes and aliases that provide efficient and safe synchronization out of the box:

If you need more control, platform-specific integration, or lower-level performance tuning, the library also provides spin-based mutexes, wrappers for native system APIs, scoped lock templates, and advanced mutex types with lock-state tracking.

Atomics#

Atomic types are essential for building safe and performant multithreaded applications. They allow shared data to be accessed and modified concurrently without introducing race conditions.

This atomic system provides a general-purpose Atomic<Type> template that automatically selects the most suitable underlying implementation: lock-free or mutex-based, depending on the size and type of the provided Type. This selection is fully resolved at compile time.

Notice
Use the generic Atomic<T> template as your default choice. It automatically selects the most efficient implementation (lock-free or mutex-based) based on the type at compile time.

The Atomic<Type> template chooses between several internal implementations using type traits and size evaluations. The decision logic is based on both type category (integer, pointer, etc.) and data size, with specific checks for 8-bit, 16-bit, 32-bit, and 64-bit sizes. Based on this, a suitable raw storage type is chosen:

  • AtomicInteger<Type>

    Used for standard integer types up to 64 bits (like int, short, long long, etc.), except for bool. This type supports atomic arithmetic and bitwise operations and is always lock-free.

  • AtomicPointer<Type>

    Specialized for pointer types. Supports atomic pointer arithmetic and CAS operations. Also lock-free and size-aware.

  • AtomicLockFree<Type>

    For all other trivially copyable types up to 64 bits:

  • AtomicWithMutex<Type>

    Fallback for types larger than 64 bits or not trivially copyable. This version is not lock-free but supports any type.

To simplify usage the following aliases are provided:

Source code (C++)
// Boolean
using AtomicBool = Atomic<bool>;

// Signed integers
using AtomicInt8   = Atomic<char>;
using AtomicInt16  = Atomic<short>;
using AtomicInt32  = Atomic<int>;
using AtomicInt64  = Atomic<long long>;

// Unsigned integers
using AtomicUInt8  = Atomic<unsigned char>;
using AtomicUInt16 = Atomic<unsigned short>;
using AtomicUInt32 = Atomic<unsigned int>;
using AtomicUInt64 = Atomic<unsigned long long>;

// Floating point
using AtomicFloat  = Atomic<float>;
using AtomicDouble = Atomic<double>;

Articles in This Section

The information on this page is valid for UNIGINE 2.20 SDK.

Last update: 10.07.2025
Build: ()