I read and re-read the MS docs about this but I'm not sure how to define my critical sections.
Will it reasonable to just put CAutoLock at the beginning of every filter method
I did experience a deadlock and I solved it by locking the code that contains a Stop method. May I conclude that every Stop has to be placed in a Critical Section

Thank you

Re: DirectShow Development Threadlocks and deadlocks

Thore Karlsen

Unfortunately, this can get very complex, and you should be very careful where and how you place your locks. You can't just put a CAutoLock at the beginning of each method, because you can get into deadlocks that way. There are a couple of things that should help you understand how to use locks appropriately in filters. First, you should read the following:

You should also look at the base classes if you're unsure.

The thing to remember is that deadlocks are caused by threads grabbing the locks in the wrong order. This scenario is a common cause of deadlocks in filters:

1. Thread A grabs the filter lock

2. Thread B grabs the streaming lock

3. Thread A tries to grab the streaming lock

4. Thread B tries to grab the filter lock

Thread A and thread B will both be waiting for the lock the other thread owns, and there is no way for progress to be made by either thread. On the other hand, if both threads always grab the filter lock first, then the streaming lock, there can be no deadlock in this situation. To make sure you never get in a situation like this you need to refer to the documentation and the base classes to see which threads are used where.