This page has been translated automatically.
视频教程
界面
要领
高级
实用建议
基础
专业(SIM)
UnigineEditor
界面概述
资源工作流程
Version Control
设置和首选项
项目开发
调整节点参数
Setting Up Materials
设置属性
照明
Sandworm
使用编辑器工具执行特定任务
如何擴展編輯器功能
嵌入式节点类型
Nodes
Objects
Effects
Decals
光源
Geodetics
World Nodes
Sound Objects
Pathfinding Objects
Players
编程
基本原理
搭建开发环境
使用范例
C++
C#
UnigineScript
统一的Unigine着色器语言 UUSL (Unified UNIGINE Shader Language)
Plugins
File Formats
材质和着色器
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
Tutorials

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: 2025-07-10
Build: ()