Why can't I use juce::Atomic with bool?

Why can’t I use juce::Atomic with bool?

../../../../modules/juce/modules/juce_core/memory/juce_Atomic.h: In instantiation of ‘juce::Atomic<Type>::~Atomic() [with Type = bool]’:
../../../../modules/gin/modules/gin/utilities/gin_downloadmanager.cpp:9:58:   required from here
../../../../modules/juce/modules/juce_core/memory/juce_Atomic.h:58:24: error: static assertion failed: This class can only be used for lock-free types
         static_assert (std::atomic<Type>::is_always_lock_free,

You should be able to. I use it. That assert hits if this flag is set:
__cpp_lib_atomic_is_always_lock_free
and the __cpp_lib_atomic_is_always_lock_free flag for that type is set.
But I don’t know what sets those flags, or what their use cases are.
I’m guessing it’s related to a build setting?

@g-mon on which platform are you getting this error? If it is on macOS, then this might be due to the OSX deployment target.

Debian Buster on Arm

There is a SO post why bool is not lockfree (but std::atomic_flag is)

Now since juce::Atomic is only a wrapper around std::atomic, maybe there could be a specialisation for juce::Atomic that uses std::atomic_flag?

But even then I don’t know if that would be possible on your platform…

I’ve rewritten my code to use std::atomic, but in general why does juce::Atomic have the additional requirement of being lock free? Just seems to make the class less useful.

So that it can be used by the realtime audio thread without causing the audio thread to be blocked

2 Likes