Mutex in unreal engine
Unreal engine has a mutex class called FCriticalSection which is a wrapper around FCriticalSectionBase which is a wrapper around FCriticalSectionPosix or FCriticalSectionWindows depending on the platform.
They are two types of mutexes in unreal engine:
FCriticalSectionwhich is a mutex that can be locked and unlockedFScopeLockwhich is a mutex that is locked when created and unlocked when destroyed
FCriticalSection Example
cpp
class A
{
public:
FCriticalSection m;
mutable int a;
void change() const
{
m.Lock();
a = 10;
m.Unlock();
}
};FScopeLock Example
cpp
class A
{
public:
FCriticalSection m;
mutable int a;
void change() const
{
FScopeLock lock(&m);
a = 10;
}
};FScopeLock is a class that locks a mutex when created and unlocks it when destroyed.