TCriticalSection not working
Posted on 2006-05-10
I made a little test program to test the working of critical sections, but it doesn't give the result I want.
I have 2 forms with each a button on. When clicking buIncrease, the program counts from 0 to 100. When it is counting and the couter is at 50 (eg) , i click on the button on the second form, wich calls the same function of when clicking the first button. The result is that the label laThread1Status displays 0 to 50 and then counts from 0 to 100 (which is done by the second call), and when it reaches 100, it restarts counting from 50 to 100 (which is the first call that is resumed).
The criticalsection should make sure that the first call first has to be completed, no..?
void __fastcall TForm1::buIncreaseClick(TObject *Sender)
int max = 100;
laThread1Status->Caption = "running: "+IntToStr(i);
laThread1Status->Caption = "finished";
void __fastcall TForm2::Button2Click(TObject *Sender)