> On Nov 30, 2023, at 4:14 AM, Dmitry Bely <[email protected]> wrote:
>
> Hi,
> Recent versions of live555 use std::atomic_flag array to work with
> event triggers. Consider the following code fragment:
>
> #ifndef NO_STD_LIB
> if (fTriggersAwaitingHandling[i].test()) {
> fTriggersAwaitingHandling[i].clear();
> #else
>
> It is problematic in two ways: 1) it's not atomic: the value can be
> changed elsewhere between test() and clear()
What you’re missing here is that the event loop (which contains the code that
you quote above) is intended to be run only by a single thread. See
http://live555.com/liveMedia/faq.html#threads
The *only* LIVE555 code that is meant to ever be run in a separate thread
(i.e., other than the thread that runs the event loop) is “triggerEvent()”,
which calls
fTriggersAwaitingHandling[i].test_and_set()
I.e., a non-event-loop thread can only ever set an atomic flag (using the
atomic operation “test_and_set()”); it cannot clear it.
> and 2) it requires C++>=20.
No it doesn’t ‘require’ C++>=20. The code should be supported on any compiler
that supports "std::atomic_flag”. That seems to include all recent versions of
clang, BTW.
But if you don’t have "std::atomic_flag”, you can compile the code with
-DNO_STD_LIB, and it should still work OK if you are using multiple threads as
intended - i.e. running all LIVE555 code - except for “triggerEvent()” - in a
single thread.
Ross Finlayson
Live Networks, Inc.
http://www.live555.com/
_______________________________________________
live-devel mailing list
[email protected]
http://lists.live555.com/mailman/listinfo/live-devel