Hi, The attached program works well under Linux when compiled with Kylix3. It counts from 1 to 10 and ends. FPC compiles it, but doesn't work (loops forever). Seems that CheckSynchronize doesn't work (or perhaps TThread.Synchronize?).
Another issue: CheckSynchronize has in Kylix3 an optional parameter (Timeout: Integer = 0), not available in FPC. Regards, Pedro
program testsync; {$ifdef FPC} {$mode delphi} {$threading on} {$endif} uses Classes, SysUtils, {$ifdef FPC}cthreads,{$endif} Libc; type Tester = class private counter: Integer; public procedure count; procedure run; end; MyThread = class(TThread) private worker: Tester; public constructor Create(w: Tester); procedure Execute; override; end; constructor MyThread.Create(w: Tester); begin worker:= w; inherited Create(false); end; procedure MyThread.Execute; begin WriteLn('Starting MyThread.Execute'); repeat Synchronize(worker.count); until Terminated; WriteLn('Ending MyThread.Execute'); end; procedure Tester.count; begin WriteLn('Starting Tester.count'); Inc(counter); WriteLn(counter); end; procedure Tester.run; var thread: MyThread; begin WriteLn('Starting Tester.run'); thread := MyThread.Create(Self); While counter < 10 do begin Sleep(100); CheckSynchronize; WriteLn('Loop inside Tester.run'); end; thread.Terminate; WriteLn('Ending Tester.run'); end; var t: Tester; begin t := Tester.Create; t.run; end.
_______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel