There is code for threads. And the creation of multiple threads with different input parameters. How to define each thread its local variables?
Now I do it as follows:
ThreadDead = class(TThread) protected procedure Execute; override; public constructor Create(startnum: integer; step: integer; endnum: integer); end; var th1, th2: ThreadDead; mut: THandle; ThreadVar sn, stp, en: integer; constructor ThreadDead.Create(startnum, step, endnum: integer); begin inherited Create(false); FreeOnTerminate:=True; sn:=startnum; stp:=step; en:=endnum; end; procedure ThreadDead.Execute; begin while sn<en do begin WaitForSingleObject(mut,infinite); form1.out.Lines.Add(inttostr(sn)); sn:=sn+stp; ReleaseMutex(mut); end; end; procedure TForm1.FormCreate(Sender: TObject); begin mut:=CreateMutex(nil,false,''); th1:=ThreadDead.Create(0, 2, 100); th2:=ThreadDead.Create(1, 2, 100); th1.Execute; th2.Execute; end; As a result, the output is the following: 1, 3, 5, ..., 95, 97, 99.
Please help solve the problem.
Expected output: 0, 1, 2, ..., 97, 98, 99.
inherited Create(false);the value has changed, nowExecuteseems to be justified. - SaheR