I’m a little bit lost in multithreading application I’m analysing. I supposed that function I’m trying to understand acts in main thread. To be sure I have placed enter and exit critical section code in it. The same critical section is also used in program startup (enter critical section) and termination (leave critical section).
Correct me if I’m wrong. If my function acts in main thread, critical section should allow to be entered. But it is not so – my functions just stops on entering critical section. According to my understanding this function acts in another thread.
Is my method correct for understanding which function acts in which thread?
Just use the debugger. Set a breakpoint in the startup code of your app, or in any message handler in your app, and check the current thread id in the debugger threads window. Then set a breakpoint in the function in question, and check the thread id when execution reaches that function. If they don’t match, then the function is not being called on the same thread that your UI messages are running on.
While you’re stopped in your function in the debugger, you can take a look at the call stack window to see the sequence of calls that led to your function call. This may provide some insight into how you got there, and how you got there on a different thread.