Understanding Locks and Threading in Gstreamer?

Nicolas Dufresne nicolas at ndufresne.ca
Tue Feb 20 18:36:57 UTC 2024


Le mardi 20 février 2024 à 16:22 +0000, Will McElderry via gstreamer-devel a
écrit :
>  
> Hi All,
>  
> I'd like to understand more about the locks and threads in GStreamer.
>  
> Can anyone point me to some docs or code to read to help get a grip on it all?
>  
> 
>  
>  
> I've read this that mentions it's important to understand about the
> application and streaming threads, and this that mentions 'the STREAM_LOCK' in
> various places. I think I've read a few other pages that reference these
> topics too, but haven't found anything that gives a good grounding about
> what's behind the design.
>  
> I've definitely fallen foul of issues from not understanding enough of these
> low-level details while trying to move up the learning curve and use signals
> to trigger actions. Sometimes I've had lock-ups immediately every time and
> sometimes it has taken a few thousand runs to spot the impact of a race
> condition, so I'd love to get clarity!

You may also want to review this one, as its about the mechanism in place
for thread safety.  You can get a visual overview of what a streaming thread is.
>From there, I must admit the doc is a bit unclear, but each time a streaming
thread activates (that data/serialized events is being pushed or pulled), each
visited pads get their stream_lock (a recursive mutex) held. This ensure that no
one can modify the links and pad state while data is flowing. As a side effect,
you have to take great care of what you are doing when you are being called back
from one of these threads, as you may endup in impossible situations like
deadlock due to this implicit locking.

Nicolas
>  
> 
>  
>  
> Thanks for reading and all the help so far!
>  
> Will.
>  

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20240220/bbbe6ca1/attachment.htm>


More information about the gstreamer-devel mailing list