Is there any issue using C++ native mutex's

I have a need to use the functionality of a waithandle for my Unreal project. Basically I need to block a thread until a waithandle is signaled by another thread. The other thread is not started by the current thread, so I can’t know when it runs. So essentially I’ll have a thread set a waithandle and then wait for that waithandle to be signaled.
I don’t see any Unreal-specific implementation of this (Critical Section won’t work as it only locks other threads’ access to the mutex but won’t block the current thread). This would work fine using C++ condition_variable. Is there any concern using it in an Unreal project? Also if there’s an Unreal implementation that exists that I’m missing, please let me know.

Thanks.

I’m using condition_variable without issue (in a FRunnable thread), but I haven’t shipped my project so I can’t guarantee it’s going to work 100% in the final product. However I don’t really see a reason why it wouldn’t.

It may also depends on which platforms you are planning on shipping your project.

There is FSemaphore. It’s not the same as a condition_variable, but can be used to achieve similar things.

Thanks kaiagan. I couldn’t figure out how to use FSemaphore. It’s defined as an abstract struct, so I can’t use it directly. Would be great if someone could provide an example of its use.

I haven’t used it myself, mind you, so I’m not the best person to answer. It should work like this:

FPlatformProcess::FSemaphore* Semaphore = FPlatformProcess::NewInterprocessSynchObject(TEXT("myName"), true);

// Wait
Semaphore->Lock();

// Release
Semaphore->Unlock();

// Important: delete when not needed anymore
FPlatformProcess::DeleteInterprocessSynchObject(Semaphore);

What I was saying still stands regarding platforms: I’m not too sure which platforms support semaphores or not. If you build for a platform that doesn’t implement it, it will fall back to the FGenericPlatformProcess which, as you mentioned, isn’t actually implement (and will actually log a fatal: FGenericPlatformProcess::NewInterprocessSynchObject not implemented on this platform). It’s definitely available for Windows, if that’s what you are using and targeting.