johngro
2016/03/01 01:31:39
While idempotent in a purely single threaded world
While idempotent in a purely single threaded world, this is not thread safe.
I think that it is perfectly reasonable to say that it needs to be neither
idempotent nor thread-safe as this code should probably be called only once very
early in an application's main. By this argument, you could remove the
initialized flag entirely and just call av_register_all().
If you want some protection against an accidental double call, you could use
std::atomic to do a compare and exchange, and then DCHECK that the method was
not already called. This enforces the call-once requirement, and is thread-safe
for practically no cost (even though it should not need to, since the rule is
probably call-once only).
If it should be possible from an API perspective to call this multiple times,
then this becomes more complicated to make thread safe. One would need to both
avoid the double init, but also use a synchronization primitive of some form to
ensure that the post-condition (FFmpeg has been fully initialized) has been met
before the second call to init exits.
On 2016/03/01 01:31:39, johngro wrote:
> While idempotent in a purely single threaded world, this is not thread safe.
>
> I think that it is perfectly reasonable to say that it needs to be neither
> idempotent nor thread-safe as this code should probably be called only once
very
> early in an application's main. By this argument, you could remove the
> initialized flag entirely and just call av_register_all().
>
> If you want some protection against an accidental double call, you could use
> std::atomic to do a compare and exchange, and then DCHECK that the method was
> not already called. This enforces the call-once requirement, and is
thread-safe
> for practically no cost (even though it should not need to, since the rule is
> probably call-once only).
>
> If it should be possible from an API perspective to call this multiple times,
> then this becomes more complicated to make thread safe. One would need to
both
> avoid the double init, but also use a synchronization primitive of some form
to
> ensure that the post-condition (FFmpeg has been fully initialized) has been
met
> before the second call to init exits.
Issue 1686363002: Motown: ffmpeg implementations of framework 'parts'
(Closed)
Created 4 years, 10 months ago by dalesat
Modified 4 years, 9 months ago
Reviewers: jamesr, jeffbrown, johngro, smklein
Base URL: https://github.com/domokit/mojo.git@master
Comments: 71