I would like to confirm here if I understand correctly how TCriticalSection and Synchronize .
As far as I know, Synchronize now uses SendMessage (updates: or at least uses it in older versions of VCL, as mentioned in a few comments below), which pauses the execution of the current thread (like any other thread) unlike PostMessage , which does not and does not perform the required function (from the main thread). In the SendMessage method, multithreading is stopped during execution.
But I'm not sure about TCriticalSection . Say, for example, I am creating something like this:
Now, my question is: how does the critical section โknowโ that I protect MyVariable1 in this case, and also regardless of what the called function can change?
If I understood it correctly - this is not so - and I must correctly call Acquire () on any thread that wants to change MyVariable1 or call this function (or make either of the two). In other words, I think of TCriticalSection as a user block that defines what I logically assigned to it. It can be a set of variables or any specific function if I call Acquire () on all threads that can write to this block or use this function. For example, โDiskOpโ might be my name TCriticalSection , which writes to disk, โInternetโ might be the name TCriticalSection , which calls functions that extract some data from the Internet. Did I understand correctly?
Also, in this context, should TCriticalSection always be a global kind of variable?
Coder12345
source share