mark_c wrote:but, I still have many doubts.
That is because you don't seem to understand how threads actually work in general.
mark_c wrote:I add another method, MyCycle, to understand which of the two threads does MyCycle for example:
Thread1 or Thread2?
Whichever thread context it is called it.
mark_c wrote:And the Label1, is accessed a quantum of time by each Thread?
I don't understand what you are asking.
mark_c wrote:notes: I tried to use GetCurrentThreadId () to understand which of the two threads is using the MyCycle () method every time but I think it only displays the ID of the UI thread
That is because you are calling GetCurrentThreadId() in the context of the UI thread only, never in the context of the worker threads, because you are synchronizing MyCycle(). The whole purpose of Synchronize() is to execute a method in the context of the UI thread, not in the context of the worker thread that is calling Synchronize(). GetCurrentThreadId() returns the ID of the thread that is calling it, which in your case is the UI thread.
Use the TThread::ThreadID property instead:
- Code: Select all
Form1->Label2->Caption = this->ThreadID;//GetCurrentThreadId();